* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    font-family: Arial, Helvetica, sans-serif;
    background: #f5f7fb;
    color: #1c2430;
    line-height: 1.5;
}

body.nav-open {
    overflow: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    max-width: 100%;
    height: auto;
}

textarea {
    resize: vertical;
}

/* Auth pages */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 460px;
    background: #ffffff;
    border-radius: 20px;
    padding: 32px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.auth-card h1 {
    margin: 0 0 8px;
}

.subtext,
.auth-link,
.empty-state,
.project-card p,
.topbar p,
.panel-head p,
.muted {
    color: #64748b;
}

/* Forms */
.form-stack {
    display: grid;
    gap: 16px;
}

.inline-form {
    display: grid;
    gap: 16px;
}

label {
    display: grid;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
}

input,
textarea,
select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #d7dfeb;
    border-radius: 12px;
    font-size: 14px;
    background: #ffffff;
    color: #1c2430;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: #0f766e;
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 12px;
    padding: 12px 16px;
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
    text-decoration: none;
    transition: background 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.btn-primary {
    background: #0f766e;
    color: #ffffff;
}

.btn-primary:hover {
    background: #0b5f59;
}

.btn-secondary {
    background: #e8eef6;
    color: #1c2430;
}

.btn-secondary:hover {
    background: #dbe5f1;
}

.btn-small {
    padding: 10px 14px;
    font-size: 13px;
}

.btn-danger {
    background: #dc2626;
    color: #fff;
    border: 1px solid #dc2626;
}

.btn-danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
    color: #fff;
}

/* Alerts */
.alert {
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 18px;
    font-size: 14px;
}

.alert.error {
    background: #fef2f2;
    color: #b91c1c;
}

.alert.success {
    background: #ecfdf5;
    color: #047857;
}

/* App layout */
.app-layout {
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    min-width: 260px;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1100;
    background: #0f172a;
    color: #ffffff;
    border-right: 1px solid #1e293b;
    padding: 24px 18px;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform 0.3s ease;
}

.sidebar-brand {
    margin-bottom: 24px;
}

.sidebar-brand h2 {
    margin: 0 0 6px;
    font-size: 24px;
    line-height: 1.2;
    color: #ffffff;
}

.sidebar-brand p {
    margin: 0;
    font-size: 14px;
    color: #cbd5e1;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 24px;
}

.nav-link {
    display: block;
    padding: 11px 14px;
    border-radius: 10px;
    text-decoration: none;
    color: #e2e8f0;
    font-size: 15px;
    line-height: 1.4;
    font-weight: 600;
    transition: background 0.2s ease, color 0.2s ease;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

.nav-link.active {
    background: #0f766e;
    color: #ffffff;
}

.main-content {
    min-width: 0;
    margin-left: 260px;
    background: #f5f7fb;
}

.main-inner {
    max-width: 1240px;
    margin: 0 auto;
    padding: 24px;
}

/* Mobile nav button */
.mobile-nav-toggle {
    display: none;
    position: fixed;
    top: 14px;
    right: 14px;
    left: auto;
    z-index: 1102;
    width: 46px;
    height: 46px;
    border: none;
    border-radius: 10px;
    background: #0f172a;
    padding: 10px;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
}

.mobile-nav-toggle span {
    display: block;
    width: 100%;
    height: 3px;
    background: #ffffff;
    border-radius: 999px;
    margin: 5px 0;
}

.sidebar-overlay {
    display: none;
}

/* Top sections */
.topbar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 24px;
}

.topbar h1,
.panel-head h2 {
    margin: 0 0 8px;
}

.topbar-actions,
.button-row,
.project-card-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* Panels */
.panel {
    background: #ffffff;
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
    margin-bottom: 24px;
}

.panel-head {
    margin-bottom: 20px;
}

/* Grids */
.two-col {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.full-row {
    grid-column: 1 / -1;
}

.card-grid,
.projects-grid,
.saved-schema-list,
.schema-group,
.cluster-list {
    display: grid;
    gap: 16px;
}

.card-grid {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.project-layout {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 24px;
    margin-bottom: 24px;
}

/* Cards */
.project-card,
.saved-schema-card,
.cluster-card {
    display: block;
    background: #ffffff;
    border: 1px solid #e4ebf5;
    border-radius: 18px;
    padding: 20px;
}

.project-card h3,
.saved-schema-card h3,
.cluster-card h3 {
    margin-top: 0;
    margin-bottom: 10px;
}

.project-card-main {
    display: block;
    color: inherit;
}

.project-meta,
.cluster-count {
    color: #64748b;
    font-size: 14px;
}

/* SERP preview */
.serp-preview {
    border: 1px solid #dbe3ee;
    border-radius: 18px;
    padding: 20px;
    background: #ffffff;
}

.serp-url {
    font-size: 14px;
    color: #64748b;
    margin: 0 0 10px;
    word-break: break-word;
}

.serp-preview h3 {
    margin: 0 0 10px;
    color: #1a0dab;
    font-size: 22px;
    line-height: 1.35;
    font-weight: 500;
}

.serp-description {
    margin: 0;
    color: #4b5563;
    line-height: 1.6;
    font-size: 14px;
}

/* Tables */
.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table,
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table {
    min-width: 980px;
}

th,
td,
.data-table th,
.data-table td {
    text-align: left;
    padding: 14px 12px;
    border-bottom: 1px solid #e7edf6;
    vertical-align: top;
    font-size: 14px;
}

th,
.data-table th {
    color: #475569;
    font-size: 13px;
    font-weight: 700;
    background: #f8fafc;
}

.truncate-cell {
    max-width: 260px;
    word-break: break-word;
}

.actions-cell {
    white-space: nowrap;
}

.table-link {
    margin-right: 12px;
    font-weight: 700;
    color: #0f766e;
}

.table-link.delete-link {
    color: #b91c1c;
}

/* Stats / score badges */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: #ffffff;
    border: 1px solid #e4ebf5;
    border-radius: 20px;
    padding: 22px;
}

.stat-label {
    margin: 0 0 10px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
}

.stat-card h2 {
    margin: 0;
    font-size: 34px;
    line-height: 1.1;
    color: #0f172a;
}

.stat-card h2.stat-small {
    font-size: 22px;
    line-height: 1.3;
}

.stat-subtext {
    display: block;
    margin-top: 10px;
    color: #64748b;
    font-size: 14px;
}

.score-good {
    background: #eaf8ef;
    color: #177245;
}

.score-mid {
    background: #fff4df;
    color: #9a6700;
}

.score-low {
    background: #fdecec;
    color: #b42318;
}

.score-none,
.delta-none {
    background: #eef2f7;
    color: #64748b;
}

/* Code output */
.code-output {
    width: 100%;
    min-height: 420px;
    font-family: Consolas, Monaco, monospace;
    font-size: 13px;
    line-height: 1.5;
    background: #0f172a;
    color: #e2e8f0;
    border: 1px solid #1e293b;
    border-radius: 16px;
    padding: 16px;
}

.json-preview {
    max-width: 420px;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
    line-height: 1.45;
    color: #475467;
    background: #f8fafc;
    border: 1px solid #e7ebf3;
    border-radius: 10px;
    padding: 10px 12px;
}

/* Responsive */
@media (max-width: 1024px) {
    .mobile-nav-toggle {
        display: block;
    }

    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        max-width: 85vw;
        border-right: 0;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.25);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        z-index: 1090;
        background: rgba(15, 23, 42, 0.5);
    }

    .sidebar-overlay.show {
        display: block;
    }

    .main-content {
        margin-left: 0;
    }

    .main-inner {
        padding: 80px 24px 24px;
    }
}

@media (max-width: 900px) {
    .two-col,
    .project-layout,
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .topbar {
        flex-direction: column;
    }
}

@media (max-width: 640px) {
    .sidebar {
        width: 88vw;
        max-width: 320px;
        padding: 20px 16px;
    }

    .nav-link {
        font-size: 14px;
        padding: 10px 12px;
    }

    .sidebar-brand h2 {
        font-size: 22px;
    }

    .main-inner {
        padding: 80px 16px 16px;
    }

    .panel,
    .auth-card {
        padding: 20px;
    }

    .btn,
    .btn-small {
        width: 100%;
    }
}