/* ==========================================================================
   Law Firm Management System — Application shell foundation
   Arabic-first, RTL by default. Uses CSS logical properties so the same
   rules mirror automatically when [dir="ltr"] is used for English later.
   ========================================================================== */

:root {
    --color-bg: #f5f6f8;
    --color-surface: #ffffff;
    --color-border: #d9dce1;
    --color-text: #1f2430;
    --color-text-muted: #5b6270;
    --color-primary: #1d5f8a;
    --color-primary-dark: #154764;
    --color-secondary: #6c757d;
    --color-success: #1e7e34;
    --color-success-bg: #e6f4ea;
    --color-warning: #8a6d1d;
    --color-warning-bg: #fdf4e3;
    --color-danger: #a4222c;
    --color-danger-bg: #fbe7e9;
    --radius: 8px;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 1rem;
    --space-4: 1.5rem;
    --space-5: 2.5rem;
    --font-sans: "Segoe UI", Tahoma, "Cairo", Arial, sans-serif;
    --focus-ring: 0 0 0 3px rgba(29, 95, 138, 0.35);
}

/* Dark palette: applied either when the OS/browser prefers dark and there is
   no explicit override (:not([data-theme="light"])), or when the visitor (or
   the firm-wide default) explicitly picked dark ([data-theme="dark"]). Same
   variable set in both places since "system says dark" and "pinned to dark"
   should look identical — only the trigger differs. RTL is unaffected by
   either rule: direction comes from [dir], color from these variables, and
   the two never interact. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --color-bg: #14171d;
        --color-surface: #1c212a;
        --color-border: #30363f;
        --color-text: #e8eaed;
        --color-text-muted: #9ba3af;
        --color-primary: #5fb0dd;
        --color-primary-dark: #8fd0f0;
        --color-secondary: #9aa1ad;
        --color-success: #5cc98a;
        --color-success-bg: #163424;
        --color-warning: #e0b84d;
        --color-warning-bg: #3a2f13;
        --color-danger: #e8707a;
        --color-danger-bg: #3a1418;
        --focus-ring: 0 0 0 3px rgba(95, 176, 221, 0.45);
    }
}
:root[data-theme="dark"] {
    --color-bg: #14171d;
    --color-surface: #1c212a;
    --color-border: #30363f;
    --color-text: #e8eaed;
    --color-text-muted: #9ba3af;
    --color-primary: #5fb0dd;
    --color-primary-dark: #8fd0f0;
    --color-secondary: #9aa1ad;
    --color-success: #5cc98a;
    --color-success-bg: #163424;
    --color-warning: #e0b84d;
    --color-warning-bg: #3a2f13;
    --color-danger: #e8707a;
    --color-danger-bg: #3a1418;
    --focus-ring: 0 0 0 3px rgba(95, 176, 221, 0.45);
}

*, *::before, *::after { box-sizing: border-box; }

html { direction: rtl; }
html[dir="ltr"] body { font-family: var(--font-sans); }
body { transition: background-color 0.15s ease, color 0.15s ease; }

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--color-primary); }

.skip-link {
    position: absolute;
    inset-inline-start: -999px;
    top: 0;
    background: var(--color-primary);
    color: #fff;
    padding: var(--space-2) var(--space-3);
    z-index: 1000;
}
.skip-link:focus {
    inset-inline-start: var(--space-2);
    top: var(--space-2);
}

:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius);
}

/* ---------- Header / Nav ---------- */
.app-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-3) var(--space-4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.app-header__brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-primary-dark);
    text-decoration: none;
}

.navbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.navbar__toggle {
    display: none;
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-2);
    cursor: pointer;
}

.navbar__list {
    list-style: none;
    display: flex;
    gap: var(--space-3);
    margin: 0;
    padding: 0;
}

.navbar__list a {
    text-decoration: none;
    color: var(--color-text);
    padding: var(--space-2) var(--space-1);
}

.navbar__list a:hover,
.navbar__list a:focus-visible {
    color: var(--color-primary);
}

.navbar__inline-form { display: inline-flex; }
.navbar .btn { padding: var(--space-1) var(--space-3); font-size: 0.9rem; }

/* ---------- Layout ---------- */
.app-main {
    flex: 1;
    width: 100%;
    max-width: 1100px;
    margin-inline: auto;
    padding: var(--space-4);
}

.app-footer {
    text-align: center;
    padding: var(--space-3);
    color: var(--color-text-muted);
    font-size: 0.875rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
}

/* ---------- Breadcrumb ---------- */
.breadcrumb {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    padding: 0;
    margin: 0 0 var(--space-4);
    color: var(--color-text-muted);
    font-size: 0.9rem;
}
.breadcrumb li:not(:last-child)::after {
    content: "\\";
    margin-inline-start: var(--space-1);
}
.breadcrumb a { text-decoration: none; }

/* ---------- Cards / sections ---------- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
}
.card h2 {
    margin-top: 0;
    font-size: 1.1rem;
}
.card--narrow { max-width: 560px; margin-inline: auto; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: var(--space-2) var(--space-3);
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-bg); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.9); }

/* ---------- Alerts ---------- */
.alert {
    border-radius: var(--radius);
    padding: var(--space-3);
    margin-bottom: var(--space-3);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
    border: 1px solid transparent;
}
.alert-success { background: var(--color-success-bg); color: var(--color-success); border-color: var(--color-success); }
.alert-warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: var(--color-warning); }
.alert-error   { background: var(--color-danger-bg); color: var(--color-danger); border-color: var(--color-danger); }
.alert__dismiss {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    color: inherit;
}

/* ---------- Forms ---------- */
.form-group { margin-bottom: var(--space-3); }
.form-label { display: block; margin-bottom: var(--space-1); font-weight: 600; }
.form-control {
    width: 100%;
    padding: var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
    background: var(--color-surface);
    color: var(--color-text);
}
.form-control:focus-visible { border-color: var(--color-primary); }
.form-error { color: var(--color-danger); font-size: 0.875rem; margin-top: var(--space-1); }
.form-hint { color: var(--color-text-muted); font-size: 0.875rem; margin-top: var(--space-1); }

/* ---------- Table ---------- */
.table-wrapper { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--color-surface); }
.table th, .table td {
    text-align: start;
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--color-border);
}
.table th { background: var(--color-bg); font-weight: 600; }

/* ---------- Layout utilities (header rows, inline filter bars, meta grids) ---------- */
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.inline-fields { display: flex; align-items: flex-end; gap: var(--space-3); flex-wrap: wrap; }
.inline-fields .form-group { margin-bottom: 0; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-4); }
.stacked-list { list-style: none; padding: 0; margin: 0; }
.stacked-list > li { margin-bottom: var(--space-2); }
.response__meta { margin: 0 0 var(--space-1); font-weight: 600; }
.response__body { margin: 0; }

/* ---------- Pagination ---------- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    margin-top: var(--space-4);
}
.pagination__status { color: var(--color-text-muted); font-size: 0.9rem; }

/* ---------- Visually hidden (still read by screen readers) ---------- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 18, 25, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--space-3);
    z-index: 100;
}
.modal-backdrop.is-open { display: flex; }
.modal {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: var(--space-4);
    max-width: 480px;
    width: 100%;
}
.modal__header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-3); }

/* ---------- States ---------- */
.state-box {
    text-align: center;
    padding: var(--space-5) var(--space-3);
    color: var(--color-text-muted);
    border: 1px dashed var(--color-border);
    border-radius: var(--radius);
}
.state-box--error { color: var(--color-danger); border-color: var(--color-danger); }

.spinner {
    width: 1.5rem;
    height: 1.5rem;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    margin: 0 auto var(--space-2);
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .navbar__toggle { display: inline-flex; }
    .navbar__list {
        position: absolute;
        inset-inline: 0;
        top: 100%;
        background: var(--color-surface);
        border-bottom: 1px solid var(--color-border);
        flex-direction: column;
        padding: var(--space-3) var(--space-4);
        display: none;
    }
    .navbar__list.is-open { display: flex; }
    .app-main { padding: var(--space-3); }
}
