/* Design tokens */
:root {
    --bg: #f4f5f9;
    --surface: #ffffff;
    --border: #e4e7ec;
    --border-strong: #cfd4dc;
    --text: #1f2937;
    --text-muted: #6b7280;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: #eef2ff;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --danger-border: #fecaca;
    --success: #047857;
    --success-soft: #ecfdf5;
    --success-border: #a7f3d0;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
    --shadow-lg: 0 10px 25px rgba(16, 24, 40, 0.08), 0 4px 10px rgba(16, 24, 40, 0.06);
    --radius: 10px;
    --radius-sm: 6px;
}

* { box-sizing: border-box; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* Header & nav */
.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 12px 32px;
    display: flex;
    align-items: center;
    gap: 32px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: inherit;
    flex-shrink: 0;
}

.brand-mark {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.5px;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.brand-text strong {
    font-size: 14px;
    font-weight: 600;
}

.brand-text .subtitle {
    font-size: 11px;
    color: var(--text-muted);
}

.nav {
    display: flex;
    gap: 4px;
    flex: 1;
    align-items: center;
}

.nav-link {
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.nav-link:hover { background: #f3f4f6; color: var(--text); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }

/* Nav dropdown groups */
.nav-group {
    position: relative;
    display: inline-flex;
}

.nav-trigger {
    background: none;
    border: 0;
    cursor: pointer;
    font: inherit;
    line-height: 1.5;
}

.nav-caret {
    transition: transform 0.15s;
    opacity: 0.7;
}
.nav-group.open .nav-caret { transform: rotate(180deg); }
.nav-group.open > .nav-trigger { background: #f3f4f6; color: var(--text); }
.nav-group.open > .nav-trigger.active { background: var(--primary-soft); color: var(--primary); }

.nav-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 240px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s;
    z-index: 60;
}
.nav-group.open > .nav-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.nav-menu-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text);
    transition: background 0.12s;
}
.nav-menu-item:hover { background: #f3f4f6; }
.nav-menu-item.active { background: var(--primary-soft); }
.nav-menu-item.active .nav-menu-title { color: var(--primary); }

.nav-menu-icon {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    background: var(--primary-soft);
    color: var(--primary);
    display: grid;
    place-items: center;
    font-size: 14px;
    flex-shrink: 0;
}

.nav-menu-title {
    display: block;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
}

.nav-menu-sub {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.logout-form { margin: 0; }

/* Layout */
.app-main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px 32px 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.page-heading {
    margin: 4px 4px 0;
}
.page-heading h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
}
.page-heading .subtitle {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--text-muted);
}

/* Card */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.step {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.step-num {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    display: grid;
    place-items: center;
    font-weight: 600;
    font-size: 13px;
    flex-shrink: 0;
}

.card h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-sub {
    margin: 2px 0 0;
    color: var(--text-muted);
    font-size: 13px;
}

.toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

/* Buttons */
.btn {
    background: var(--primary);
    color: #fff;
    border: 0;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s, transform 0.05s;
}
.btn:hover:not(:disabled) { background: var(--primary-hover); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.secondary { background: #6b7280; }
.btn.secondary:hover:not(:disabled) { background: #4b5563; }
.btn.danger { background: var(--danger); }
.btn.danger:hover:not(:disabled) { background: #b91c1c; }

.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-block { display: block; width: 100%; padding: 10px 14px; font-size: 14px; }

.link {
    background: none;
    border: 0;
    padding: 0;
    color: var(--primary);
    font: inherit;
    cursor: pointer;
    text-decoration: underline;
}
.link:hover { color: var(--primary-hover); }

/* Chips */
.chip {
    display: inline-flex;
    align-items: center;
    padding: 1px 10px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.7;
}
.chip.muted {
    background: #f3f4f6;
    color: var(--text-muted);
    font-weight: 500;
}

/* Dropzone */
.dropzone {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius);
    background: #fafbff;
    transition: border-color 0.15s, background 0.15s;
    cursor: pointer;
    padding: 32px 24px;
}
.dropzone:hover,
.dropzone:focus-visible {
    border-color: var(--primary);
    outline: none;
}
.dropzone.dragging {
    border-color: var(--primary);
    background: var(--primary-soft);
}
.dropzone.busy { opacity: 0.6; pointer-events: none; }

.dropzone-inner { text-align: center; }

.dropzone-icon {
    width: 44px;
    height: 44px;
    margin: 0 auto 10px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    display: grid;
    place-items: center;
    font-size: 20px;
    font-weight: 700;
}

.dropzone-title { font-size: 14px; font-weight: 500; color: var(--text); }
.dropzone-hint { margin-top: 4px; font-size: 12px; color: var(--text-muted); }

/* Grid */
.grid { height: 380px; width: 100%; }

/* Status banner */
.status {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-muted);
    background: #f8fafc;
    border: 1px solid var(--border);
    display: none;
}
.status:not(:empty) { display: block; }
.status.error {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: var(--danger-border);
}
.status.success {
    color: var(--success);
    background: var(--success-soft);
    border-color: var(--success-border);
}

/* Progress */
.progress {
    margin-top: 14px;
    width: 100%;
    height: 22px;
    background: #e5e7eb;
    border-radius: 999px;
    overflow: hidden;
    position: relative;
    display: none;
}
.progress.active { display: block; }
.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #2563eb, #7c3aed);
    transition: width 0.2s ease;
}
.progress-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.muted { color: var(--text-muted); font-size: 13px; }

/* Toast notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    max-width: calc(100vw - 40px);
}
.toast {
    min-width: 280px;
    max-width: 420px;
    padding: 12px 14px;
    border-radius: var(--radius-sm, 8px);
    background: #fff;
    border: 1px solid var(--border);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.10);
    font-size: 13px;
    line-height: 1.45;
    color: var(--text);
    pointer-events: auto;
    display: flex;
    gap: 10px;
    align-items: flex-start;
    animation: toast-slide-in 0.18s ease-out;
}
.toast.warning {
    border-color: #f59e0b;
    background: #fffbeb;
    color: #92400e;
}
.toast.success {
    border-color: var(--success-border);
    background: var(--success-soft);
    color: var(--success);
}
.toast.error {
    border-color: var(--danger-border);
    background: var(--danger-soft);
    color: var(--danger);
}
.toast .toast-msg { flex: 1; word-break: break-word; white-space: pre-line; }
.toast .toast-close {
    border: 0;
    background: transparent;
    cursor: pointer;
    color: inherit;
    font-size: 18px;
    line-height: 1;
    padding: 0 2px;
    opacity: 0.55;
}
.toast .toast-close:hover { opacity: 1; }
.toast.dismissing { animation: toast-slide-out 0.18s ease-in forwards; }
@keyframes toast-slide-in {
    from { transform: translateX(20px); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}
@keyframes toast-slide-out {
    from { transform: translateX(0); opacity: 1; }
    to   { transform: translateX(20px); opacity: 0; }
}

/* Dashboard */
.tile-section + .tile-section { margin-top: 24px; }

.tile-section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 4px;
    margin-bottom: 12px;
}

.tile-section-mark {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 12px;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.tile-section-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.tile-section-sub {
    margin: 2px 0 0;
    font-size: 12px;
    color: var(--text-muted);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}

.dashboard-tile {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: inherit;
    background: var(--surface);
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.05s;
}
.dashboard-tile:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow);
}

.tile-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: var(--primary-soft);
    color: var(--primary);
    display: grid;
    place-items: center;
    font-size: 20px;
    flex-shrink: 0;
}

.dashboard-tile h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}
.dashboard-tile p {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--text-muted);
}

/* Auth */
.auth-body {
    background: linear-gradient(180deg, #f4f5f9 0%, #eef2ff 100%);
    min-height: 100vh;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 32px;
}

.auth-brand {
    text-align: center;
    margin-bottom: 24px;
}
.auth-brand .brand-mark {
    margin: 0 auto 12px;
}
.auth-brand h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}
.auth-sub {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--text-muted);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.field input[type="text"],
.field input[type="password"],
.field input[type="email"] {
    padding: 9px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.field-error {
    font-size: 12px;
    color: var(--danger);
}

.field-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
}

/* Responsive */
@media (max-width: 760px) {
    .header-inner { padding: 10px 16px; gap: 16px; flex-wrap: wrap; }
    .brand-text .subtitle { display: none; }
    .nav { order: 3; flex-basis: 100%; overflow-x: visible; flex-wrap: wrap; }
    .nav-group { width: 100%; }
    .nav-group .nav-trigger { width: 100%; justify-content: space-between; }
    .nav-menu {
        position: static;
        box-shadow: none;
        border: 0;
        padding: 4px 0 4px 12px;
        min-width: 0;
        opacity: 1;
        visibility: visible;
        transform: none;
        display: none;
    }
    .nav-group.open > .nav-menu { display: block; }
    .app-main { padding: 16px; }
    .card-header { flex-direction: column; align-items: stretch; }
    .toolbar { justify-content: flex-end; }
    .grid { height: 320px; }
    .auth-card { padding: 24px; }
}
