*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 'Helvetica Neue', Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    background: #f1f5f9;
    color: #1e293b;
}

/* ---- Layout ---- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    padding: 32px 40px;
    min-width: 0;
}

/* ---- Sidebar ---- */

.sidebar {
    width: 220px;
    flex-shrink: 0;
    background: #0f172a;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar__header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,.06);
}

.sidebar__brand {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #e2e8f0;
}

.sidebar__nav {
    flex: 1;
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar__nav-link {
    display: flex;
    align-items: center;
    padding: 9px 12px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    color: #94a3b8;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background .12s, color .12s;
}

.sidebar__nav-link:hover {
    background: rgba(255,255,255,.06);
    color: #e2e8f0;
}

.sidebar__nav-link--active {
    background: rgba(99,102,241,.18);
    color: #c7d2fe;
    border-left-color: #6366f1;
    font-weight: 600;
}

.sidebar__footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,.06);
}

.sidebar__logout {
    background: none;
    border: none;
    color: #64748b;
    cursor: pointer;
    padding: 0;
    font-size: 13px;
    font-family: inherit;
    display: block;
}

.sidebar__logout:hover {
    color: #94a3b8;
}

/* ---- Page header ---- */

.page-header {
    margin-bottom: 28px;
}

.page-header__back {
    display: inline-block;
    font-size: 13px;
    color: #64748b;
    text-decoration: none;
    margin-bottom: 4px;
}

.page-header__back:hover {
    color: #1e293b;
    text-decoration: underline;
}

.page-header h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.25;
}

.page-header .nav-links {
    margin-top: 14px;
    margin-bottom: 0;
}

/* ---- Cards ---- */

.card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    padding: 24px;
    margin-bottom: 20px;
    overflow: hidden;
}

.card__header {
    margin: -24px -24px 20px;
    padding: 13px 24px;
    border-bottom: 1px solid #f1f5f9;
    background: #f8fafc;
    border-radius: 10px 10px 0 0;
}

.card__header h2 {
    margin: 0;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #64748b;
}

/* ---- Dashboard stat grid ---- */

.grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.grid .card {
    text-align: center;
}

.grid .card h3 {
    margin: 0 0 4px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #64748b;
}

.grid .card span {
    display: block;
    font-size: 32px;
    font-weight: 700;
    color: #0f172a;
    margin-top: 4px;
}

/* ---- Dashboard compact metrics ---- */

.dashboard-metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.dashboard-metric-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    padding: 14px 16px;
    text-align: center;
}

.dashboard-metric-card strong {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #64748b;
    margin-bottom: 4px;
}

.dashboard-metric-card span {
    display: block;
    font-size: 22px;
    font-weight: 700;
    color: #0f172a;
}

/* ---- Dashboard top summary row ---- */

.dashboard-summary-row {
    display: flex;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.dashboard-db-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    padding: 10px 16px;
    display: flex;
    align-items: center;
}

/* ---- Tables ---- */

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table th,
.table td {
    text-align: left;
    padding: 11px 14px;
    border-bottom: 1px solid #f1f5f9;
}

.table thead th {
    font-weight: 600;
    color: #64748b;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .06em;
    background: #fafafa;
}

.table tbody tr:hover {
    background: #f8fafc;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table--detail th {
    width: 160px;
    color: #64748b;
    font-weight: 600;
    font-size: 13px;
    text-transform: none;
    letter-spacing: 0;
    background: transparent;
}

.table--detail td {
    color: #1e293b;
}

.table a {
    color: #4f46e5;
    text-decoration: none;
}

.table a:hover {
    text-decoration: underline;
}

.table code {
    font-family: ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, monospace;
    font-size: 12px;
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    color: #334155;
}

.table__action {
    text-align: right;
    white-space: nowrap;
    width: 1px;
}

.table__action a,
.table__action-btn {
    color: #4f46e5;
    font-weight: 500;
    font-size: 13px;
}

.table__action-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    margin-left: 0.75rem;
}

/* ---- Badges ---- */

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge--ok {
    background: #dcfce7;
    color: #166534;
}

.badge--error {
    background: #fee2e2;
    color: #991b1b;
}

.badge--active {
    background: #dcfce7;
    color: #166534;
}

.badge--inactive {
    background: #f1f5f9;
    color: #64748b;
}

.badge--planned {
    background: #e0e7ff;
    color: #3730a3;
}

.badge--paused {
    background: #fef9c3;
    color: #854d0e;
}

.badge--archived {
    background: #f1f5f9;
    color: #475569;
}

.badge--default {
    background: #ede9fe;
    color: #5b21b6;
}

.badge--status {
    background: #f1f5f9;
    color: #374151;
}

.badge--generated {
    background: #dbeafe;
    color: #1e40af;
}

.badge--selected {
    background: #dcfce7;
    color: #166534;
}

.badge--rejected {
    background: #f1f5f9;
    color: #64748b;
}

.badge--draft {
    background: #f1f5f9;
    color: #475569;
}

.badge--review {
    background: #dbeafe;
    color: #1e40af;
}

.badge--revision {
    background: #fef3c7;
    color: #92400e;
}

.badge--approved {
    background: #dcfce7;
    color: #166534;
}

.badge--scheduled {
    background: #ede9fe;
    color: #5b21b6;
}

.badge--published {
    background: #d1fae5;
    color: #065f46;
}

.badge--failed {
    background: #fee2e2;
    color: #991b1b;
}

.badge--queued {
    background: #dbeafe;
    color: #1e40af;
}

.badge--processing {
    background: #fef3c7;
    color: #92400e;
}

.badge--draft_created {
    background: #d1fae5;
    color: #065f46;
}

.badge--posted {
    background: #dcfce7;
    color: #166534;
}

.badge--retry {
    background: #ffedd5;
    color: #9a3412;
}

.badge--manual_required {
    background: #fee2e2;
    color: #b91c1c;
}

/* ---- Auth layout ---- */

.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #f1f5f9;
}

.auth-wrap {
    width: 100%;
    max-width: 400px;
    padding: 24px;
}

.auth-card__title {
    font-size: 20px;
    font-weight: 700;
    margin: 0 0 24px;
    color: #0f172a;
}

/* ---- Forms ---- */

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: #374151;
}

.form-group label.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 400;
    cursor: pointer;
}

.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="time"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #d1d5db;
    border-radius: 7px;
    font-size: 14px;
    color: #1e293b;
    background: #ffffff;
    font-family: inherit;
    transition: border-color .12s, box-shadow .12s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

.form-group textarea {
    resize: vertical;
}

.form-group input[type="number"] {
    max-width: 140px;
}

.form-group input[type="time"] {
    max-width: 160px;
}

.form-static {
    margin: 0;
    padding: 9px 0;
    font-size: 14px;
    color: #374151;
    font-weight: 500;
}

/* ---- Form max-width (app layout) ---- */

.main-content .card > form {
    max-width: 660px;
}

/* ---- Form actions row ---- */

.form-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid #f1f5f9;
}

/* ---- Buttons ---- */

.btn {
    display: inline-block;
    padding: 9px 18px;
    border: none;
    border-radius: 7px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    text-decoration: none;
    line-height: 1.5;
    white-space: nowrap;
}

.btn--primary {
    background: #4f46e5;
    color: #ffffff;
}

.btn--primary:hover {
    background: #4338ca;
}

.btn--secondary {
    background: #f8fafc;
    color: #374151;
    border: 1px solid #e2e8f0;
}

.btn--secondary:hover {
    background: #f1f5f9;
    color: #111827;
}

.auth-wrap .btn {
    width: 100%;
    text-align: center;
}

/* ---- Alerts ---- */

.alert {
    padding: 12px 16px;
    border-radius: 7px;
    margin-bottom: 16px;
    font-size: 14px;
    border-left: 4px solid;
}

.alert--error {
    background: #fef2f2;
    color: #991b1b;
    border-color: #f87171;
}

.alert--success {
    background: #f0fdf4;
    color: #166534;
    border-color: #4ade80;
}

/* ---- Nav links (brand show section pills) ---- */

.nav-links {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    margin-bottom: 20px;
}

.nav-links a {
    display: inline-block;
    padding: 5px 12px;
    border-radius: 6px;
    background: #f1f5f9;
    color: #374151;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid #e2e8f0;
}

.nav-links a:hover {
    background: #e2e8f0;
    color: #111827;
}

/* ---- Meta / timestamp ---- */

.meta {
    font-size: 13px;
    color: #94a3b8;
    margin: 0;
}

/* ---- Responsive ---- */

@media (max-width: 900px) {
    .sidebar { width: 200px; }
    .main-content { padding: 24px 28px; }
}

@media (max-width: 640px) {
    .app-shell { flex-direction: column; }
    .sidebar {
        width: 100%;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
        position: static;
        height: auto;
        overflow-y: visible;
    }
    .sidebar__header {
        padding: 12px 16px;
        border-bottom: none;
        border-right: 1px solid rgba(255,255,255,.06);
    }
    .sidebar__nav {
        flex-direction: row;
        padding: 8px;
        gap: 4px;
        flex: 1;
    }
    .sidebar__nav-link {
        padding: 7px 10px;
        border-left: none;
        border-bottom: 3px solid transparent;
        font-size: 13px;
    }
    .sidebar__nav-link--active {
        border-left-color: transparent;
        border-bottom-color: #6366f1;
    }
    .sidebar__footer {
        padding: 8px 12px;
        border-top: none;
        border-left: 1px solid rgba(255,255,255,.06);
    }
    .main-content { padding: 16px; }
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; text-align: center; }
    .grid { grid-template-columns: 1fr; }
}
