:root {
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --border: #dbe3ee;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --success: #15803d;
    --danger: #b91c1c;
    --warning: #b45309;
    --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
    --radius: 18px;
    --radius-sm: 12px;
    --sidebar: #0b1220;
    --sidebar-muted: rgba(229, 238, 251, 0.72);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top left, rgba(15, 118, 110, 0.16), transparent 32%),
        linear-gradient(180deg, #f3f7fb 0%, #eef3f8 100%);
    color: var(--text);
    min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
code {
    background: #eef2f7;
    padding: 0.15rem 0.35rem;
    border-radius: 8px;
    font-size: 0.92em;
}

.app-shell {
    display: grid;
    grid-template-columns: 280px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: linear-gradient(180deg, var(--sidebar), #111827);
    color: #e5eefb;
    padding: 1.4rem;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.brand {
    display: flex;
    gap: 0.9rem;
    align-items: center;
}
.brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    background: linear-gradient(135deg, #14b8a6, #0ea5e9);
    display: grid;
    place-items: center;
    font-weight: 800;
    color: white;
    letter-spacing: 0.04em;
}
.brand-title { font-weight: 700; line-height: 1.15; }
.brand-subtitle, .user-email { color: rgba(229, 238, 251, 0.7); font-size: 0.92rem; }

.user-card {
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.04);
    padding: 1rem;
}
.user-name { font-weight: 700; margin-bottom: 0.2rem; }

.nav { display: grid; gap: 0.4rem; }
.nav-link {
    color: #dbe7fb;
    padding: 0.85rem 1rem;
    border-radius: 14px;
    transition: background 0.15s ease, transform 0.15s ease;
}
.nav-link:hover, .nav-link.is-active {
    background: rgba(255, 255, 255, 0.09);
    transform: translateX(2px);
}
.logout-form { margin-top: auto; }

.main-content {
    padding: 1.5rem;
    max-width: 1700px;
    width: 100%;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1.2rem;
}
.topbar h1 {
    margin: 0;
    font-size: clamp(1.4rem, 2vw, 2rem);
}
.eyebrow {
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.72rem;
    font-weight: 800;
    margin-bottom: 0.35rem;
}
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.pill {
    display: inline-flex;
    align-items: center;
    padding: 0.65rem 0.9rem;
    border-radius: 999px;
    background: #eef4fb;
    color: #334155;
    font-weight: 700;
    font-size: 0.9rem;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    margin-bottom: 1.2rem;
}
.page-header h1 {
    margin: 0;
    font-size: clamp(1.7rem, 2vw, 2.35rem);
}
.page-header p {
    margin: 0.4rem 0 0;
    color: var(--muted);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}
.stat-card, .panel, .auth-card {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(219, 227, 238, 0.9);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.stat-card {
    padding: 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}
.stat-card.is-blue { border-top: 4px solid #2563eb; }
.stat-card.is-green { border-top: 4px solid #16a34a; }
.stat-card.is-yellow { border-top: 4px solid #ca8a04; }
.stat-card span { color: var(--muted); font-size: 0.94rem; }
.stat-card strong { font-size: 1.8rem; line-height: 1; }

.panel {
    padding: 1rem;
    margin-bottom: 1rem;
}
.panel.tight { padding-bottom: 0.9rem; }
.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.85rem;
}
.panel-head h2 { margin: 0; font-size: 1.1rem; }
.panel-head a { font-size: 0.94rem; }

.panel-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.table-wrap {
    overflow: auto;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: white;
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 960px;
}
.data-table th, .data-table td {
    padding: 0.9rem 0.8rem;
    border-bottom: 1px solid #edf2f7;
    text-align: left;
    vertical-align: top;
    font-size: 0.94rem;
}
.data-table th {
    background: var(--surface-soft);
    color: #334155;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.data-table tr:hover td { background: #fafcff; }

.truncate {
    max-width: 260px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.empty-state {
    padding: 1.4rem;
    color: var(--muted);
    text-align: center;
}

.btn {
    border: 0;
    border-radius: 999px;
    padding: 0.8rem 1.05rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); color: white; }
.btn-ghost { background: transparent; color: inherit; border: 1px solid rgba(255, 255, 255, 0.2); }
.btn-ghost-light { background: #f8fafc; color: #0f172a; border: 1px solid #dbe3ee; }
.btn-small {
    padding: 0.55rem 0.85rem;
    font-size: 0.9rem;
    background: #0f172a;
    color: white;
}

.alert {
    border-radius: 14px;
    padding: 0.95rem 1rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
}
.alert-success { background: #ecfdf5; border-color: #bbf7d0; color: #166534; }
.alert-danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }

.toolbar {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: end;
    margin-bottom: 0.9rem;
}
.filter-form {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.8rem;
    width: 100%;
}
.filter-form .actions {
    display: flex;
    gap: 0.6rem;
    align-items: end;
    flex-wrap: wrap;
}
.search-box {
    flex: 1 1 320px;
}
.search-box input {
    width: 100%;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.34rem 0.65rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: capitalize;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-muted { background: #e2e8f0; color: #334155; }

.form-grid {
    display: grid;
    gap: 1rem;
}
.form-grid-two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid label {
    display: grid;
    gap: 0.45rem;
}
.form-grid span {
    font-size: 0.88rem;
    color: var(--muted);
    font-weight: 600;
}
input, select, textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0.85rem 0.95rem;
    font: inherit;
    background: white;
    color: var(--text);
}
textarea.code-block {
    min-height: 140px;
    resize: vertical;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid rgba(15, 118, 110, 0.2);
    border-color: rgba(15, 118, 110, 0.6);
}
.span-2 { grid-column: span 2; }
.form-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}
.action-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}
.inline-form { display: inline-flex; margin: 0; }
.search-hint {
    color: var(--muted);
    font-size: 0.9rem;
    margin: 0.2rem 0 0;
}

.auth-body {
    display: grid;
    place-items: center;
    padding: 1.5rem;
}
.auth-card {
    width: min(100%, 460px);
    padding: 1.5rem;
}
.auth-brand {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1.2rem;
}
.auth-brand h1 {
    margin: 0;
    font-size: 1.5rem;
}
.auth-brand p {
    margin: 0.35rem 0 0;
    color: var(--muted);
}

.copy-btn { min-width: 84px; }

@media (max-width: 1280px) {
    .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .panel-grid { grid-template-columns: 1fr; }
    .filter-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 960px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: sticky; top: 0; z-index: 10; }
    .main-content { padding: 1rem; }
    .page-header, .topbar { align-items: flex-start; flex-direction: column; }
    .form-grid-two, .span-2 { grid-column: span 1; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
    .stats-grid { grid-template-columns: 1fr; }
    .data-table { min-width: 780px; }
    .sidebar { padding: 1rem; }
    .filter-form { grid-template-columns: 1fr; }
}
