@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Noto+Kufi+Arabic:wght@400;500;600;700&display=swap');

* { box-sizing: border-box; }

body {
    font-family: 'Inter', 'Noto Kufi Arabic', sans-serif;
    background: #f4f6f9;
    color: #1f2937;
    margin: 0;
}

/* Top nav */
.navbar {
    background: #0d2219;
    color: #fff;
    padding: 14px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.navbar a {
    color: #cbd5e1;
    text-decoration: none;
    margin-inline-start: 20px;
    font-size: 14px;
    font-weight: 500;
}
.navbar a:hover { color: #fff; }
.navbar .brand {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.5px;
}
.navbar .brand span { color: #4ade80; }
.navbar form button {
    background: none;
    border: none;
    color: #cbd5e1;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
}
.navbar form button:hover { color: #fff; }

/* Layout */
.page {
    max-width: 1100px;
    margin: 32px auto;
    padding: 0 24px;
}
.card {
    background: #fff;
    border-radius: 10px;
    padding: 24px 28px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    margin-bottom: 24px;
}
h1 { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
h2 { font-size: 16px; font-weight: 600; margin: 28px 0 12px; color: #374151; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
    text-align: start;
    background: #f8fafc;
    color: #6b7280;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 10px 14px;
    border-bottom: 1px solid #e5e7eb;
}
td {
    padding: 12px 14px;
    border-bottom: 1px solid #f1f5f9;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }
table a { color: #16a34a; text-decoration: none; font-weight: 500; }
table a:hover { text-decoration: underline; }

/* Buttons */
button, .btn {
    background: #16a34a;
    color: #fff;
    border: none;
    padding: 9px 18px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    text-decoration: none;
    display: inline-block;
}
button:hover, .btn:hover { background: #15803d; }
.btn-secondary { background: #fff; color: #374151; border: 1px solid #d1d5db; }
.btn-secondary:hover { background: #f9fafb; }
.btn-danger { background: #fff; color: #dc2626; border: 1px solid #fca5a5; }
.btn-danger:hover { background: #fef2f2; }
a.back-link {
    color: #6b7280;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    display: inline-block;
    margin-bottom: 16px;
}
a.back-link:hover { color: #374151; }

/* Flips the literal arrow character used in back-links (wrapped via a
   templates-wide find/replace: &larr; -> <span class="back-arrow">&larr;</span>)
   so "back" visually points toward the reading-start direction in RTL. */
.back-arrow {
    display: inline-block;
}
[dir="rtl"] .back-arrow {
    display: inline-block;
    transform: scaleX(-1);
}

/* Forms */
input[type=text], input[type=search], input[type=email], input[type=password], input[type=date], input[type=number], textarea, select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    margin-top: 4px;
}
label {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    display: block;
    margin-bottom: 4px;
}
form p { margin-bottom: 16px; }

/* Status badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin: 16px 0 4px;
}
.meta-item .label { font-size: 11px; text-transform: uppercase; color: #9ca3af; font-weight: 600; letter-spacing: 0.4px; }
.meta-item .value { font-size: 14px; font-weight: 500; margin-top: 2px; }

.detail-layout {
    display: flex;
    gap: 24px;
    align-items: flex-start;
}
.detail-main {
    flex: 1;
    min-width: 0;
}
.detail-sidebar {
    width: 220px;
    flex-shrink: 0;
}
.detail-sidebar .card { padding: 18px; }
.detail-sidebar h2 {
    margin: 0 0 14px;
    font-size: 14px;
}
.detail-sidebar .btn, .detail-sidebar .btn-secondary {
    display: block;
    width: 100%;
    text-align: center;
    margin-bottom: 10px;
    box-sizing: border-box;
}
.detail-sidebar .btn:last-child, .detail-sidebar .btn-secondary:last-child {
    margin-bottom: 0;
}
@media (max-width: 720px) {
    .detail-layout { flex-direction: column; }
    .detail-sidebar { width: 100%; }
}

.detail-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 0;
    border-bottom: 1px solid #e5e7eb;
}
.detail-tab-btn {
    background: none;
    border: none;
    padding: 12px 18px;
    font-size: 14px;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    font-family: inherit;
}
.detail-tab-btn:hover { color: #1f2937; background: none; }
.detail-tab-btn.active {
    color: #16a34a;
    border-bottom-color: #16a34a;
}
.detail-tab-panel { display: none; }
.detail-tab-panel.active { display: block; }
.stat-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    margin-top: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background: #ffffff;
    border-radius: 10px;
    padding: 14px 16px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
    border-inline-start: 4px solid #d8dce6;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.1);
}

.stat-value {
    font-size: 24px;
    font-weight: 800;
    color: #1a1a2e;
    line-height: 1;
}

.stat-label {
    margin-top: 6px;
    font-size: 11px;
    font-weight: 600;
    color: #7a7f8d;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.1);
}


.empty-state {
    color: #7a7f8d;
    padding: 20px 0;
    text-align: center;
}
.alert-error {
    background: #fff5f5;
    border: 1px solid #feb2b2;
    color: #c53030;
    border-radius: 8px;
    padding: 12px 16px;
    margin: 16px 0;
    font-size: 14px;
}

/* RTL script polish: letter-spacing is a Latin-typography convention that
   visually breaks Arabic letterforms (it forces gaps between connected
   letters), and uppercase transforms are meaningless for Arabic. Both are
   harmless to reset globally under [dir="rtl"]. */
[dir="rtl"] th,
[dir="rtl"] .expiry-table th,
[dir="rtl"] .approvals-table th,
[dir="rtl"] .stat-label,
[dir="rtl"] .meta-item .label,
[dir="rtl"] .navbar .brand {
    letter-spacing: normal;
}
/* ---------- App shell: top bar + left sidebar ---------- */
.navbar {
    position: sticky;
    top: 0;
    z-index: 50;
    height: 60px;
    padding: 0 24px;
}
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}
.navbar a.topbar-new {
    margin: 0;
    background: #16a34a;
    color: #fff;
    padding: 7px 14px;
    border-radius: 8px;
    font-weight: 600;
}
.navbar a.topbar-new:hover { background: #15803d; color: #fff; }

/* Profile button + dropdown */
.profile-menu { position: relative; }
.profile-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.18);
    color: #e2e8f0;
    padding: 4px 10px 4px 4px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 500;
}
.profile-btn:hover { background: rgba(255,255,255,0.16); }
[dir="rtl"] .profile-btn { padding: 4px 4px 4px 10px; }
.profile-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #16a34a;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}
.profile-avatar-lg { width: 40px; height: 40px; font-size: 15px; }
.profile-panel {
    position: absolute;
    inset-inline-end: 0;
    top: calc(100% + 8px);
    width: 260px;
    background: #fff;
    color: #1f2937;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
    border: 1px solid #e5e7eb;
    padding: 14px 16px;
    z-index: 60;
}
.profile-panel-head { display: flex; align-items: center; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid #f1f5f9; }
.profile-panel-name { font-weight: 600; font-size: 14px; }
.profile-panel-sub { color: #6b7280; font-size: 12px; word-break: break-all; }
.profile-panel-list { margin: 10px 0 0; font-size: 13px; }
.profile-panel-list dt { color: #9ca3af; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; margin-top: 6px; }
.profile-panel-list dd { margin: 2px 0 0; font-weight: 500; }

/* Sidebar */
.app-shell { display: flex; align-items: flex-start; }
.sidebar {
    position: sticky;
    top: 60px;
    height: calc(100vh - 60px);
    width: 220px;
    flex-shrink: 0;
    background: #fff;
    border-inline-end: 1px solid #e5e7eb;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
}
.side-link {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    color: #374151;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    background: none;
    border: none;
    text-align: start;
    font-family: inherit;
    cursor: pointer;
}
.side-link svg { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.side-link:hover { background: #f1f5f9; color: #111827; }
.side-link.active { background: #f0fdf4; color: #16a34a; font-weight: 600; }
.side-logout { margin-top: auto; border-top: 1px solid #f1f5f9; padding-top: 8px; }
.side-logout .side-link { color: #6b7280; }
.side-logout .side-link:hover { background: #fef2f2; color: #dc2626; }
.app-shell > .page { flex: 1; min-width: 0; }

.profile-panel-logout { margin: 12px 0 0; padding-top: 12px; border-top: 1px solid #f1f5f9; }
/* ".navbar" prefix: beats the older ".navbar form button" rule, which made this grey. */
.navbar .profile-panel-logout button {
    display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
    background: #fff; border: 1px solid #fca5a5; color: #dc2626;
    padding: 9px 12px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.navbar .profile-panel-logout button:hover { background: #dc2626; border-color: #dc2626; color: #fff; }


.detail-tabs { flex-wrap: wrap; }  /* wrap rather than scroll if a bar ever runs out of room */
.detail-tab-btn { white-space: nowrap; flex-shrink: 0; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Site-wide messages (e.g. "can't be deleted because ...") */
.flash-messages .alert-error, .flash-messages .alert-success { margin: 0 0 16px; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d; border-radius: 8px; padding: 12px 16px; margin: 16px 0; font-size: 14px; }

.alert-warning { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; border-radius: 8px; padding: 12px 16px; margin: 16px 0; font-size: 14px; }

/* Vault > Audit Log */
.audit-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.audit-filter-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 8px; align-items: end; }
.audit-failed { display: flex; align-items: center; min-height: 34px; }
@media (max-width: 900px) { .audit-filter-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.audit-table td { font-size: 13px; vertical-align: top; }
.audit-failed-row td { background: #fef2f2; }
.audit-fail-label { color: #b91c1c; }
.audit-changes { list-style: none; margin: 4px 0 0; padding: 0; font-size: 12px; color: #4b5563; }
.audit-field { font-weight: 600; color: #374151; }
.audit-old { color: #6b7280; text-decoration: line-through; }
.audit-new { color: #15803d; }
.audit-cat { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: #e7f6ec; color: #1f7a3f; white-space: nowrap; }
.audit-cat-signin { background: #f1f5f9; color: #334155; }
.audit-cat-license { background: #fef3c7; color: #92400e; }
.audit-cat-settings { background: #ede9fe; color: #5b21b6; }
.audit-pages { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 14px; }

/* Platform version (sidebar, sign-in page) */
.side-version { padding: 6px 12px 2px; font-size: 11px; color: #9ca3af; }
.auth-version { color: #9ca3af; margin-inline-start: 4px; }


/* Profile pictures (top bar, Vault > Users, My profile) */
.profile-avatar-img { object-fit: cover; background: #e5e7eb; display: inline-block; }
.profile-avatar-xl { width: 72px; height: 72px; font-size: 24px; }
.user-cell { display: inline-flex; align-items: center; gap: 8px; }
.me-head { display: flex; align-items: center; gap: 14px; margin: 8px 0 16px; }
.me-name { font-size: 17px; font-weight: 600; }
.me-photo { display: flex; flex-direction: column; gap: 4px; }
.me-photo input[type=file] { font-size: 13px; }
.user-form-photo { flex-direction: row; align-items: center; gap: 14px; margin-bottom: 14px; }
.user-form-photo > div { display: flex; flex-direction: column; gap: 4px; }
.me-details { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 18px 0 8px; font-size: 14px; }
.me-details dt { color: #6b7280; }
.me-details dd { margin: 0; }
.profile-panel a.profile-panel-link { display: flex; align-items: center; gap: 8px; margin: 0; padding: 8px 14px; color: #1f2937; font-size: 14px; border-top: 1px solid #f1f5f9; }
.profile-panel a.profile-panel-link:hover { background: #f8fafc; color: #15803d; }

/* ---------- Logo mark next to the "Contralio" name ---------- */
.brand-mark {
    width: 1.35em;
    height: 1.35em;
    vertical-align: middle;
    position: relative;
    top: -0.08em;
    margin-inline-end: 0.4em;
    border-radius: 0.3em;
}


/* ---------- Phones (720px and narrower): bottom tab bar, one column, no sideways page scroll ---------- */
.tabbar, .tab-sheet { display: none; }
@media (max-width: 720px) {
    html { -webkit-text-size-adjust: 100%; }
    body { overflow-x: hidden; }
    /* Top bar: compact. */
    .navbar { height: 56px; padding: 0 12px; padding-top: env(safe-area-inset-top); box-sizing: content-box; }
    .navbar .brand { font-size: 16px; }
    .topbar-actions { gap: 8px; }
    .profile-name, .profile-btn > svg { display: none; }
    .profile-btn { padding: 3px; }

    /* Side menu -> bottom tab bar. */
    .sidebar { display: none; }
    .app-shell { display: block; }
    .tabbar {
        display: flex;
        position: fixed;
        inset-inline: 0;
        bottom: 0;
        z-index: 70;
        background: #fff;
        border-top: 1px solid #e5e7eb;
        box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.06);
        padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    }
    .tabbar .tab {
        flex: 1;
        min-width: 0;
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        padding: 6px 2px;
        margin: 0;
        border: 0;
        border-radius: 10px;
        background: transparent;
        color: #64748b;
        font-size: 11px;
        font-weight: 600;
        text-decoration: none;
        cursor: pointer;
    }
    .tabbar .tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .tabbar .tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
    .tabbar .tab.active { color: #166534; }
    .tabbar .tab.active svg { stroke-width: 2.4; }
    .tab-badge {
        position: absolute;
        top: 2px;
        inset-inline-start: calc(50% + 6px);
        min-width: 18px;
        height: 18px;
        padding: 0 5px;
        border-radius: 9px;
        background: #16a34a;
        color: #fff;
        font-size: 11px;
        line-height: 18px;
        text-align: center;
        box-sizing: border-box;
    }
    .tab-badge-alert { background: #dc2626; }
    .tab-sheet {
        display: flex;
        flex-direction: column;
        position: fixed;
        inset-inline-end: 8px;
        bottom: calc(68px + env(safe-area-inset-bottom));
        z-index: 71;
        min-width: 220px;
        padding: 8px;
        background: #fff;
        border: 1px solid #e5e7eb;
        border-radius: 14px;
        box-shadow: 0 12px 32px rgba(15, 23, 42, 0.22);
    }
    .tab-sheet[hidden] { display: none; }
    .tab-sheet a, .tab-sheet button {
        display: block;
        width: 100%;
        padding: 12px 14px;
        margin: 0;
        border: 0;
        border-radius: 10px;
        background: transparent;
        color: #1f2937;
        font-size: 15px;
        font-weight: 500;
        text-align: start;
        text-decoration: none;
        cursor: pointer;
    }
    .tab-sheet a:hover, .tab-sheet button:hover { background: #f1f5f9; }
    .tab-sheet form { margin: 4px 0 0; padding-top: 4px; border-top: 1px solid #f1f5f9; }
    .tab-sheet .tab-sheet-logout { color: #dc2626; }
    .tab-sheet .tab-install { color: #166534; font-weight: 600; }
    .tab-sheet-version { padding: 6px 14px 2px; font-size: 11px; color: #9ca3af; }

    /* Page and cards: full width, room for the tab bar. */
    .page { margin: 12px auto 0; padding: 0 12px calc(84px + env(safe-area-inset-bottom)); }
    .card { padding: 16px; margin-bottom: 14px; border-radius: 12px; }
    h1 { font-size: 20px; }
    .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
    .table-scroll > table { min-width: 100%; }
    /* iPhone zooms into fields with text under 16px. */
    input[type=text], input[type=search], input[type=email], input[type=password], input[type=date],
    input[type=number], textarea, select { font-size: 16px; }

    /* Dashboard. */
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 14px 0 18px; }

    .detail-layout { flex-direction: column; align-items: stretch; gap: 0; }
    .detail-main, .detail-sidebar { width: 100%; }
    .detail-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
    .detail-tabs::-webkit-scrollbar { display: none; }
    .detail-tab-btn { white-space: nowrap; flex-shrink: 0; }




}


/* ---------- Installable app: install buttons and the iPhone tip (_pwa.html) ---------- */
.pwa-install[hidden], .ios-tip[hidden] { display: none !important; }
.navbar .profile-panel button.profile-panel-link {
    display: flex; align-items: center; gap: 8px; width: 100%; margin: 0; padding: 8px 14px;
    background: transparent; border: 0; border-top: 1px solid #f1f5f9; border-radius: 0;
    color: #166534; font-size: 14px; font-weight: 600; text-align: start; cursor: pointer;
}
.navbar .profile-panel button.profile-panel-link:hover { background: #f8fafc; }
.ios-tip {
    position: fixed;
    inset-inline: 10px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    z-index: 75;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: #0f172a;
    color: #e2e8f0;
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.35);
    font-size: 14px;
    line-height: 1.45;
}
.ios-tip span { flex: 1; }
.ios-tip .ios-tip-close { background: transparent; border: 0; color: #94a3b8; font-size: 22px; line-height: 1; padding: 2px 6px; cursor: pointer; }
/* App pages on a phone: above the tab bar and the chat button. */
@media (max-width: 720px) { body:has(.tabbar) .ios-tip { bottom: calc(140px + env(safe-area-inset-bottom)); } }

