/* ========== DESIGN TOKENS ========== */

:root {
    --bg-page: #f3f4f6;
    --bg-surface: #ffffff;
    --bg-surface-soft: #f9fafb;
    --border-subtle: #e5e7eb;
    --border-strong: #d1d5db;

    --text-main: #111827;
    --text-muted: #6b7280;
    --text-soft: #9ca3af;

    --primary: #d4a017;           /* gold */
    --primary-soft: #fef3c7;
    --primary-dark: #92400e;

    --danger: #b91c1c;
    --danger-soft: #fee2e2;

    --accent-dark: #111827;       /* header/sidebar */
    --accent-dark-soft: #1f2937;

    --radius-lg: 16px;
    --radius-md: 10px;
    --radius-sm: 6px;
    --radius-pill: 999px;

    --shadow-soft: 0 8px 20px rgba(15, 23, 42, 0.12);
    --shadow-subtle: 0 1px 3px rgba(15, 23, 42, 0.14);

    --font-base: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* ========== RESET & BASE ========== */

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

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-base);
    color: var(--text-main);
    background-color: var(--bg-page);
    -webkit-font-smoothing: antialiased;
}

/* Generic typography (works even for pages not using layout.php) */
h1, h2, h3, h4 {
    margin: 0 0 8px 0;
    font-weight: 600;
    color: var(--text-main);
}

p {
    margin: 0 0 8px 0;
    line-height: 1.5;
}

a {
    color: #1f2937;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Fallback layout for bare pages like index.php (if layout not used) */
body > h1:first-of-type {
    max-width: 960px;
    margin: 24px auto 8px auto;
    padding: 0 16px;
}

body > p,
body > form,
body > a {
    max-width: 960px;
    margin: 0 auto 8px auto;
    padding: 0 16px;
}

/* ========== HEADER / NAV ========== */

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--accent-dark);
    color: #f9fafb;
    box-shadow: var(--shadow-subtle);
}

.app-header .brand,
.app-header .app-nav {
    max-width: 1120px;
    margin: 0 auto;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-header .brand {
    flex: 1 1 auto;
    flex-direction: column;
    align-items: flex-start;
}

.brand-title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

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

.app-nav {
    flex: 0 0 auto;
    justify-content: flex-end;
    flex-wrap: wrap;
    padding-top: 0;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    margin-left: 4px;
    border-radius: var(--radius-pill);
    font-size: 13px;
    border: 1px solid transparent;
    color: #e5e7eb;
    background: transparent;
    text-decoration: none;
    transition: background 120ms ease, color 120ms ease, border 120ms ease;
}

.nav-link:hover {
    background: rgba(249, 250, 251, 0.06);
    border-color: rgba(249, 250, 251, 0.14);
}

.nav-link.is-active {
    background: rgba(249, 250, 251, 0.12);
    border-color: var(--primary);
    color: #fef3c7;
}

/* ========== GLOBAL MAIN / FOOTER WRAPPER ========== */

.app-main {
    max-width: 1120px;
    margin: 18px auto 24px auto;
    padding: 0 16px;
}

.app-main-narrow {
    max-width: 720px;
}

/* ========== SIDEBAR LAYOUT (dashboard/admin) ========== */

body.layout-sidebar {
    background: var(--bg-page);
}

.app-shell {
    max-width: 1120px;
    margin: 18px auto 24px auto;
    padding: 0 16px;
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 18px;
}

.app-sidebar {
    background: var(--accent-dark);
    color: #e5e7eb;
    border-radius: var(--radius-lg);
    padding: 14px 14px 16px 14px;
    box-shadow: var(--shadow-soft);
}

.sidebar-section + .sidebar-section {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #1f2937;
}

.sidebar-title {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-soft);
    margin-bottom: 6px;
}

.sidebar-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-list li {
    margin-bottom: 4px;
}

.sidebar-list a {
    display: block;
    padding: 7px 10px;
    border-radius: var(--radius-md);
    font-size: 13px;
    color: #e5e7eb;
    text-decoration: none;
    background: transparent;
    transition: background 120ms ease;
}

.sidebar-list a:hover {
    background: rgba(15, 23, 42, 0.7);
}

.sidebar-list a.is-active {
    background: rgba(249, 250, 251, 0.10);
    border: 1px solid rgba(212, 160, 23, 0.8);
}

/* Sidebar link shortcuts for .sidebar-link class used in layout.php */
.sidebar-link {
    display: block;
    padding: 7px 10px;
    border-radius: var(--radius-md);
    font-size: 13px;
    color: #e5e7eb;
    text-decoration: none;
    background: transparent;
    transition: background 120ms ease;
}

.sidebar-link:hover {
    background: rgba(15, 23, 42, 0.7);
}

.sidebar-link-active {
    background: rgba(249, 250, 251, 0.10);
    border: 1px solid rgba(212, 160, 23, 0.8);
}

/* ========== CARDS ========== */

.card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-soft);
    padding: 14px 16px 16px 16px;
    margin-bottom: 16px;
}

.card-secondary {
    background: var(--bg-surface-soft);
}

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

.card-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 2px;
}

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

/* ========== BUTTONS ========== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-pill);
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    background: #e5e7eb;
    color: #111827;
    transition: background 120ms ease, color 120ms ease, box-shadow 120ms ease, border 120ms ease;
}

.btn:hover {
    background: #d1d5db;
}

.btn-primary {
    background: var(--primary);
    color: #111827;
    box-shadow: var(--shadow-subtle);
}

.btn-primary:hover {
    background: #facc15;
    box-shadow: var(--shadow-soft);
}

.btn-secondary {
    background: var(--accent-dark-soft);
    color: #f9fafb;
}

.btn-secondary:hover {
    background: #020617;
}

.btn-small {
    padding: 5px 10px;
    font-size: 12px;
}

.btn:disabled {
    opacity: 0.6;
    cursor: default;
}

/* ========== BADGES ========== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    background: #e5e7eb;
    color: #374151;
}

.badge-green {
    background: rgba(22, 163, 74, 0.10);
    color: #15803d;
}

.badge-amber {
    background: rgba(217, 119, 6, 0.10);
    color: #b45309;
}

.badge-red {
    background: rgba(220, 38, 38, 0.10);
    color: #b91c1c;
}

/* ========== TABLES ========== */

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
    font-size: 13px;
}

th, td {
    padding: 7px 8px;
    border-bottom: 1px solid var(--border-subtle);
    text-align: left;
    vertical-align: top;
}

th {
    background: var(--bg-surface-soft);
    font-weight: 600;
    color: #374151;
}

tbody tr:hover {
    background: #f3f4f6;
}

/* ========== FORMS ========== */

form {
    margin: 0;
}

.form.form-vertical {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
}

label.inline {
    flex-direction: row;
    align-items: center;
    gap: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
    font-family: var(--font-base);
    font-size: 14px;
    padding: 7px 9px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-strong);
    outline: none;
    background: #f9fafb;
    transition: border 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px rgba(212, 160, 23, 0.5);
    background: #ffffff;
}

textarea {
    resize: vertical;
}

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

/* Filter row on admin dashboard */
.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    margin: 10px 0 8px 0;
}

.filter-row label {
    min-width: 140px;
}

/* ========== ALERTS ========== */

.alert {
    border-radius: var(--radius-md);
    padding: 8px 10px;
    font-size: 13px;
    margin-bottom: 10px;
}

.alert-success {
    background: #ecfdf3;
    border: 1px solid #bbf7d0;
    color: #166534;
}

.alert-error {
    background: var(--danger-soft);
    border: 1px solid #fecaca;
    color: var(--danger);
}

/* ========== SUMMARY STATS (admin & dashboard) ========== */

.summary-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 6px 0 10px 0;
}

.summary-item {
    flex: 1 1 80px;
    padding: 6px 8px;
    border-radius: var(--radius-md);
    background: var(--bg-surface-soft);
    border: 1px solid var(--border-subtle);
}

.summary-label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-soft);
    margin-bottom: 2px;
}

.summary-value {
    font-size: 16px;
    font-weight: 600;
}

/* ========== CASE VIEW ========== */

.case-body {
    padding: 10px;
    background: #f9fafb;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    white-space: pre-wrap;
    font-family: monospace;
    font-size: 13px;
    margin-bottom: 12px;
}

.answer-list {
    margin: 8px 0 12px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.answer-item {
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    background: #f9fafb;
    padding: 8px 10px;
}

.answer-meta {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 12px;
    margin-bottom: 4px;
}

.answer-author {
    font-weight: 600;
}

.answer-date {
    color: var(--text-soft);
    font-size: 11px;
}

.answer-body {
    font-size: 13px;
}

/* KB suggestions in case view */
.kb-suggestions {
    list-style: none;
    padding: 0;
    margin: 0 0 12px 0;
}

.kb-suggestions li {
    padding: 8px 10px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    background: #f9fafb;
    margin-bottom: 6px;
}

.kb-snippet {
    font-size: 12px;
    color: var(--text-muted);
}

/* Fieldset in case view */
.fieldset {
    border-radius: var(--radius-md);
    border: 1px dashed var(--border-strong);
    padding: 8px 10px 10px 10px;
    margin-top: 10px;
}

.fieldset legend {
    font-size: 12px;
    font-weight: 600;
    padding: 0 4px;
}

/* ========== FOOTER ========== */

.app-footer {
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-surface-soft);
}

.footer-inner {
    max-width: 1120px;
    margin: 0 auto;
    padding: 10px 16px 16px 16px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    color: var(--text-soft);
}

/* ========== RESPONSIVE ========== */

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: minmax(0, 1fr);
    }

    .app-sidebar {
        order: -1;
    }

    .app-main {
        margin-top: 12px;
    }

    .app-header .brand {
        padding-bottom: 4px;
    }

    .app-header .brand,
    .app-header .app-nav {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* --- HOMEPAGE UPGRADE --- */

.card-home {
    padding: 20px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.05);
    margin-top: 30px;
}

.card-home h1 {
    font-size: 26px;
    margin-bottom: 12px;
}

.card-home p {
    font-size: 15px;
    color: #4b5563;
}

/* Buttons look better full-width on homepage */
.card a.btn {
    width: 100%;
}