/* ==========================================================================
   Al-Yateem CRM — Stylesheet
   Brand: #90604e (warm brown)
   ========================================================================== */

:root {
    --brand: #90604e;
    --brand-dark: #7a4f3f;
    --brand-light: #b08a78;
    --brand-bg: #faf7f4;
    --brand-tint: #f3ebe4;
    --ink: #2d2d2d;
    --ink-soft: #5c5c5c;
    --ink-muted: #8a8a8a;
    --line: #e6dcd2;
    --line-soft: #f0e8e0;
    --bg: #ffffff;
    --bg-soft: #f9f5f1;
    --green: #2e7d32;
    --green-bg: #e8f5e9;
    --amber: #ef6c00;
    --amber-bg: #fff4e5;
    --red: #c62828;
    --red-bg: #ffebee;
    --blue: #1565c0;
    --blue-bg: #e3f2fd;
    --shadow-sm: 0 1px 2px rgba(60, 30, 15, 0.04);
    --shadow: 0 2px 8px rgba(60, 30, 15, 0.08);
    --shadow-lg: 0 8px 24px rgba(60, 30, 15, 0.12);
    --radius: 8px;
    --radius-lg: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Helvetica Neue", Arial, sans-serif;
    color: var(--ink);
    background: var(--brand-bg);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; cursor: pointer; }

input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    color: var(--ink);
}

/* === LOGIN PAGE === */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #faf7f4 0%, #ede0d3 100%);
}
.login-card {
    background: white;
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}
.login-logo {
    text-align: center;
    margin-bottom: 32px;
}
.login-logo .brand-mark {
    width: 64px;
    height: 64px;
    background: var(--brand);
    border-radius: 50%;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -1px;
}
.login-logo h1 { font-size: 24px; color: var(--brand); margin-bottom: 4px; font-weight: 700; }
.login-logo p { color: var(--ink-muted); font-size: 14px; }

/* === LAYOUT === */
.app {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: 60px 1fr;
    grid-template-areas: "sidebar topbar" "sidebar main";
    height: 100vh;
}

.sidebar {
    grid-area: sidebar;
    background: white;
    border-right: 1px solid var(--line);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-header .brand-mark {
    width: 32px; height: 32px; border-radius: 6px;
    background: var(--brand); color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px;
}
.sidebar-header .brand-text {
    font-weight: 700; color: var(--brand); font-size: 16px;
}
.sidebar nav { flex: 1; padding: 12px 8px; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border-radius: 6px;
    color: var(--ink-soft);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 2px;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
}
.nav-item:hover { background: var(--brand-tint); color: var(--ink); }
.nav-item.active { background: var(--brand); color: white; }
.nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-section {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--ink-muted);
    padding: 16px 12px 6px;
    font-weight: 600;
}

.topbar {
    grid-area: topbar;
    background: white;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
}
.topbar h2 { font-size: 18px; font-weight: 600; color: var(--ink); }
.user-menu {
    display: flex; align-items: center; gap: 12px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    position: relative;
}
.user-menu:hover { background: var(--brand-tint); }
.user-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--brand);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 13px;
}
.user-info-text { font-size: 13px; }
.user-info-text .name { font-weight: 600; }
.user-info-text .role { color: var(--ink-muted); font-size: 12px; }

.user-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: white;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    z-index: 100;
    display: none;
}
.user-dropdown.show { display: block; }
.user-dropdown button {
    display: block; width: 100%; text-align: left;
    padding: 10px 14px; border: none; background: none;
    font-size: 14px; color: var(--ink);
}
.user-dropdown button:hover { background: var(--bg-soft); }
.user-dropdown hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; }

.main {
    grid-area: main;
    overflow-y: auto;
    padding: 24px;
}

/* === BUTTONS === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 6px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    background: var(--bg);
    color: var(--ink);
    border-color: var(--line);
    white-space: nowrap;
}
.btn:hover { background: var(--bg-soft); border-color: var(--brand-light); }
.btn-primary { background: var(--brand); color: white; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { background: var(--red); color: white; border-color: var(--red); }
.btn-danger:hover { background: #a01818; border-color: #a01818; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-icon { padding: 6px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* === FORMS === */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-soft);
    margin-bottom: 6px;
}
.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 14px;
    background: white;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(144, 96, 78, 0.15);
}
textarea.form-control { min-height: 80px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-check {
    display: flex; align-items: center; gap: 8px;
    font-size: 14px; cursor: pointer;
}
.form-check input { width: 16px; height: 16px; cursor: pointer; }

/* === CARDS === */
.card {
    background: white;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 16px; }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line-soft);
}
.card-header h3 { font-size: 16px; font-weight: 600; }

/* === STAT CARDS === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    border: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 4px; height: 100%;
    background: var(--brand);
}
.stat-card.green::before { background: var(--green); }
.stat-card.amber::before { background: var(--amber); }
.stat-card.red::before { background: var(--red); }
.stat-card.blue::before { background: var(--blue); }
.stat-label {
    font-size: 12px;
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    margin-bottom: 6px;
}
.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--ink);
    line-height: 1;
}
.stat-sub {
    font-size: 12px;
    color: var(--ink-muted);
    margin-top: 6px;
}

/* === TABLES === */
.table-wrap { overflow-x: auto; }
table.data {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 14px;
}
table.data th {
    text-align: left;
    padding: 10px 12px;
    background: var(--bg-soft);
    color: var(--ink-soft);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
table.data td {
    padding: 12px;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: middle;
}
table.data tr:hover td { background: var(--bg-soft); }
table.data tr.clickable { cursor: pointer; }
table.data tr:last-child td { border-bottom: none; }

/* === BADGES === */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.badge-orphan    { background: var(--green-bg); color: var(--green); }
.badge-aftercare { background: var(--amber-bg); color: var(--amber); }
.badge-transition{ background: var(--red-bg);   color: var(--red); }
.badge-warning   { background: var(--amber-bg); color: var(--amber); }
.badge-info      { background: var(--blue-bg);  color: var(--blue); }
.badge-muted     { background: var(--line);     color: var(--ink-soft); }
.badge-not-qual  { background: var(--red-bg);   color: var(--red); }

/* === FILTER BAR === */
.filter-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
}
.filter-bar .search-input {
    flex: 1;
    min-width: 200px;
    max-width: 400px;
}

/* === MODALS === */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(45, 30, 20, 0.5);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}
.modal {
    background: white;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}
.modal-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h3 { font-size: 17px; font-weight: 600; }
.modal-close {
    background: none; border: none;
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px;
    color: var(--ink-muted);
    font-size: 22px;
    line-height: 1;
}
.modal-close:hover { background: var(--bg-soft); color: var(--ink); }
.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
}
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* === ALERTS === */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    border: 1px solid;
    font-size: 14px;
}
.alert-error { background: var(--red-bg); border-color: rgba(198,40,40,0.2); color: var(--red); }
.alert-success { background: var(--green-bg); border-color: rgba(46,125,50,0.2); color: var(--green); }
.alert-warning { background: var(--amber-bg); border-color: rgba(239,108,0,0.2); color: var(--amber); }
.alert-info { background: var(--blue-bg); border-color: rgba(21,101,192,0.2); color: var(--blue); }

/* === EMPTY STATE === */
.empty {
    padding: 48px 20px;
    text-align: center;
    color: var(--ink-muted);
}
.empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.4;
}

/* === LOADING === */
.spinner {
    width: 24px; height: 24px;
    border: 3px solid var(--line);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay {
    display: flex; align-items: center; justify-content: center;
    padding: 40px;
    color: var(--ink-muted);
    gap: 10px;
}

/* === TOAST === */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--ink);
    color: white;
    padding: 12px 18px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    animation: toast-in 0.2s ease-out;
    max-width: 360px;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
@keyframes toast-in {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* === MEMBER LIST WITHIN FAMILY VIEW === */
.member-row {
    display: grid;
    grid-template-columns: 40px 1fr auto auto auto;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 8px;
    background: white;
}
.member-row .member-num {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--brand-tint);
    color: var(--brand);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 13px;
}
.member-row .member-name { font-weight: 600; }
.member-row .member-meta {
    font-size: 12px; color: var(--ink-muted);
    margin-top: 2px;
}

/* === REGION TABS === */
.region-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
}
.region-tab {
    padding: 10px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--ink-soft);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}
.region-tab:hover { color: var(--brand); }
.region-tab.active {
    color: var(--brand);
    border-bottom-color: var(--brand);
    font-weight: 600;
}

/* === RESPONSIVE === */
@media (max-width: 800px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-rows: 60px 1fr;
        grid-template-areas: "topbar" "main";
    }
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100%;
        width: 240px;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform 0.2s;
    }
    .sidebar.open { transform: translateX(0); }
    .menu-toggle { display: block !important; }
    .form-row { grid-template-columns: 1fr; }
}
.menu-toggle { display: none; background: none; border: none; padding: 8px; }

/* RTL support for Arabic names */
[dir="auto"], .rtl-content { unicode-bidi: plaintext; }

/* utility */
.text-muted { color: var(--ink-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-2 { margin-top: 16px; } .mb-2 { margin-bottom: 16px; }
.flex { display: flex; }
.gap-2 { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
