/* =====================================================================
   rofofi Control-Plane — Admin Dashboard
   Light, modern theme (Tajawal). RTL.
   ===================================================================== */

:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --title: #0f172a;
    --text: #334155;
    --muted: #94a3b8;
    --border: #eef2f7;
    --border-strong: #e2e8f0;

    --brand: #f97316;
    --brand-dark: #ea580c;
    --brand-soft: #fff7ed;

    --green: #16a34a;
    --green-soft: #dcfce7;
    --blue: #2563eb;
    --blue-soft: #dbeafe;
    --amber: #d97706;
    --amber-soft: #fef3c7;
    --red: #dc2626;
    --red-soft: #fee2e2;
    --slate: #64748b;
    --slate-soft: #f1f5f9;

    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 10px 30px -14px rgba(15, 23, 42, 0.20);
    --shadow-sm: 0 2px 8px -2px rgba(15, 23, 42, 0.10);
    --font: 'Tajawal', 'Cairo', 'Segoe UI', Tahoma, sans-serif;
    --sidebar-w: 256px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: 'SFMono-Regular', Consolas, monospace; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: .85em; direction: ltr; }

/* =================== Login =================== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: radial-gradient(circle at 50% 0%, #fff7ed, var(--bg)); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 36px 32px; }
.login-card .logo { text-align: center; font-size: 40px; margin-bottom: 4px; }
.login-card h1 { text-align: center; color: var(--title); font-size: 1.5rem; margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 24px; font-size: .92rem; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .82rem; color: var(--text); margin-bottom: 6px; font-weight: 700; }
.input {
    width: 100%; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
    background: var(--surface-2); color: var(--title); font-size: 15px; font-family: inherit; transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.input.ltr { direction: ltr; text-align: left; }

/* =================== Buttons =================== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
    font-family: inherit; font-size: 14px; font-weight: 700; cursor: pointer; transition: background .15s, border-color .15s, opacity .15s; white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-block { width: 100%; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover:not(:disabled) { filter: brightness(.93); }
.btn-red { background: var(--red); color: #fff; }
.btn-red:hover:not(:disabled) { filter: brightness(.93); }
.btn-amber { background: var(--amber); color: #fff; }
.btn-amber:hover:not(:disabled) { filter: brightness(.93); }
.btn-blue { background: var(--blue); color: #fff; }
.btn-blue:hover:not(:disabled) { filter: brightness(.93); }

/* =================== App layout =================== */
.app { display: flex; min-height: 100vh; }
.sidebar {
    flex: 0 0 var(--sidebar-w); background: var(--surface); border-left: 1px solid var(--border);
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 22px 22px 18px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); }
.sidebar .brand .mark { font-size: 26px; }
.sidebar .brand .name { font-weight: 800; color: var(--title); font-size: 1.15rem; }
.sidebar .brand .name small { display: block; font-size: .68rem; color: var(--muted); font-weight: 600; }
.nav { padding: 14px 12px; flex: 1; overflow-y: auto; }
.nav-label { font-size: .7rem; color: var(--muted); font-weight: 800; letter-spacing: .04em; padding: 12px 12px 6px; text-transform: uppercase; }
.nav-item {
    display: flex; align-items: center; gap: 11px; padding: 11px 12px; border-radius: var(--radius-sm);
    color: var(--text); font-weight: 700; cursor: pointer; margin-bottom: 2px; font-size: .94rem; border: none; background: none; width: 100%; text-align: right; font-family: inherit;
}
.nav-item .ic { font-size: 18px; width: 22px; text-align: center; }
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--brand-soft); color: var(--brand-dark); }
.nav-item .pill { margin-right: auto; background: var(--slate-soft); color: var(--slate); font-size: 11px; font-weight: 800; padding: 1px 8px; border-radius: 20px; }
.nav-item.active .pill { background: var(--brand); color: #fff; }
.sidebar .foot { padding: 14px 18px; border-top: 1px solid var(--border); font-size: .78rem; color: var(--muted); }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.85); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border); padding: 14px 28px; display: flex; align-items: center; gap: 16px;
}
.topbar .page-title { font-size: 1.3rem; font-weight: 800; color: var(--title); }
.topbar .page-sub { font-size: .82rem; color: var(--muted); }
.topbar .spacer { flex: 1; }
.topbar .op { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: .88rem; font-weight: 700; }
.topbar .op .avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-dark); display: flex; align-items: center; justify-content: center; font-weight: 800; }

.content { padding: 28px; flex: 1; }
.section { display: none; }
.section.active { display: block; }

/* =================== KPI cards =================== */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 22px; }
.kpi {
    background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 18px 20px;
    border: 1px solid var(--border); position: relative; overflow: hidden;
}
.kpi .kpi-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.kpi .kpi-ic { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.kpi .kpi-label { font-size: .8rem; color: var(--muted); font-weight: 700; }
.kpi .kpi-value { font-size: 1.8rem; font-weight: 800; color: var(--title); line-height: 1.15; }
.kpi .kpi-sub { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.ic-green { background: var(--green-soft); color: var(--green); }
.ic-blue { background: var(--blue-soft); color: var(--blue); }
.ic-amber { background: var(--amber-soft); color: var(--amber); }
.ic-red { background: var(--red-soft); color: var(--red); }
.ic-brand { background: var(--brand-soft); color: var(--brand-dark); }
.ic-slate { background: var(--slate-soft); color: var(--slate); }

/* =================== Cards / panels =================== */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
.card-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.card-head h2 { font-size: 1.05rem; color: var(--title); font-weight: 800; }
.card-head .h-sub { font-size: .8rem; color: var(--muted); }
.card-head .spacer { flex: 1; }
.card-body { padding: 22px; }

.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; margin-bottom: 22px; }
.grid-2.equal { grid-template-columns: 1fr 1fr; }
@media (max-width: 980px) { .grid-2, .grid-2.equal { grid-template-columns: 1fr; } }

.chart-wrap { position: relative; height: 300px; }
.chart-wrap.sm { height: 240px; }

/* =================== Tables =================== */
.table-scroll { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.tbl th {
    text-align: right; padding: 12px 16px; color: var(--muted); font-weight: 800; font-size: .76rem;
    border-bottom: 1px solid var(--border-strong); white-space: nowrap; background: var(--surface-2);
}
table.tbl td { padding: 13px 16px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
table.tbl tbody tr { transition: background .12s; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tbody tr.clickable { cursor: pointer; }
.store-cell { display: flex; flex-direction: column; gap: 2px; }
.store-cell .nm { font-weight: 700; color: var(--title); }
.store-cell .sl { font-size: .76rem; color: var(--muted); direction: ltr; }
.cell-email { color: var(--slate); font-size: .84rem; direction: ltr; }

/* =================== Badges =================== */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: .74rem; font-weight: 800; white-space: nowrap; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.b-trialing { background: var(--amber-soft); color: var(--amber); }
.b-active { background: var(--green-soft); color: var(--green); }
.b-suspended { background: var(--red-soft); color: var(--red); }
.b-past_due { background: #ffedd5; color: #c2410c; }
.b-basic { background: var(--slate-soft); color: var(--slate); }
.b-pro { background: var(--blue-soft); color: var(--blue); }
.b-enterprise { background: #f3e8ff; color: #7e22ce; }
.days { font-weight: 800; font-size: .85rem; }
.days.ok { color: var(--green); }
.days.warn { color: var(--amber); }
.days.crit { color: var(--red); }
.days.none { color: var(--muted); }

/* =================== Filters bar =================== */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.filters .search { position: relative; flex: 1; min-width: 220px; }
.filters .search .input { padding-right: 38px; }
.filters .search .si { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.filters select.input { width: auto; min-width: 140px; padding-left: 30px; }
.count-pill { background: var(--slate-soft); color: var(--slate); font-size: .76rem; font-weight: 800; padding: 5px 11px; border-radius: 20px; }

/* =================== Empty / loading =================== */
.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty .em-ic { font-size: 40px; margin-bottom: 8px; opacity: .6; }
.loading { text-align: center; padding: 40px; color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 3px solid var(--border-strong); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* =================== Toast =================== */
.toast-wrap { position: fixed; bottom: 24px; left: 24px; z-index: 999; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--title); color: #fff; padding: 13px 18px; border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: .9rem; font-weight: 700; animation: slidein .25s ease; max-width: 360px; }
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }
@keyframes slidein { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* =================== Drawer (tenant details) =================== */
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 50; opacity: 0; pointer-events: none; transition: opacity .2s; }
.overlay.open { opacity: 1; pointer-events: auto; }
.drawer {
    position: fixed; top: 0; bottom: 0; left: 0; width: min(560px, 100%); background: var(--surface); z-index: 60;
    transform: translateX(-105%); transition: transform .28s cubic-bezier(.4,0,.2,1); display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.drawer.open { transform: none; }
.drawer-head { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; gap: 12px; }
.drawer-head .dh-title { font-size: 1.2rem; font-weight: 800; color: var(--title); }
.drawer-head .dh-sub { font-size: .82rem; color: var(--muted); }
.drawer-head .x { background: none; border: none; font-size: 22px; color: var(--muted); cursor: pointer; padding: 4px; line-height: 1; margin-right: auto; }
.drawer-head .x:hover { color: var(--title); }
.drawer-body { flex: 1; overflow-y: auto; padding: 22px 24px; }
.drawer-foot { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 8px; }

.dl { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; margin-bottom: 6px; font-size: .9rem; }
.dl dt { color: var(--muted); font-weight: 700; }
.dl dd { color: var(--title); font-weight: 700; word-break: break-word; }
.sub-h { font-size: .82rem; font-weight: 800; color: var(--brand-dark); margin: 22px 0 10px; text-transform: uppercase; letter-spacing: .03em; }
.mini-tbl { width: 100%; font-size: .84rem; border-collapse: collapse; }
.mini-tbl th { text-align: right; padding: 8px 10px; color: var(--muted); font-weight: 800; border-bottom: 1px solid var(--border-strong); font-size: .74rem; }
.mini-tbl td { padding: 9px 10px; border-bottom: 1px solid var(--border); }

.stat-line { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.stat-chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 16px; flex: 1; min-width: 110px; }
.stat-chip .v { font-size: 1.25rem; font-weight: 800; color: var(--title); }
.stat-chip .l { font-size: .74rem; color: var(--muted); font-weight: 700; }

/* =================== Mobile =================== */
.menu-btn { display: none; background: none; border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; font-size: 18px; cursor: pointer; color: var(--text); }
@media (max-width: 860px) {
    .sidebar { position: fixed; z-index: 80; transform: translateX(-105%); transition: transform .25s; box-shadow: var(--shadow); }
    .sidebar.open { transform: none; }
    .menu-btn { display: inline-block; }
    .content { padding: 18px; }
    .topbar { padding: 12px 16px; }
}

/* =================== Audit log =================== */
.b-audit { background: var(--slate-soft); color: var(--slate); }
.b-audit.b-warn { background: var(--amber-soft); color: var(--amber); }
.b-audit.b-danger { background: var(--red-soft); color: var(--red); }
.b-audit.b-ok { background: var(--green-soft); color: var(--green); }
.audit-detail { font-size: .84rem; color: var(--text); }
.input-sm { padding: 6px 11px; font-size: .82rem; }
.card-head .input { background: var(--surface-2); }

/* =================== Period editor (drawer) =================== */
.period-editor {
    margin-top: 18px; padding: 16px; border: 1px dashed var(--brand);
    background: var(--brand-soft); border-radius: var(--radius-sm);
    animation: slidein .2s ease;
}
.period-editor .pe-title { font-weight: 800; color: var(--brand-dark); margin-bottom: 12px; font-size: .92rem; }
.period-editor .pe-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.period-editor .pe-row label { font-size: .76rem; font-weight: 700; color: var(--muted); }
.period-editor .pe-or { text-align: center; color: var(--muted); font-size: .74rem; font-weight: 700; margin: 6px 0; }
.period-editor .pe-check { display: flex; align-items: center; gap: 8px; margin: 8px 0 12px; cursor: pointer; font-size: .82rem; font-weight: 700; color: var(--slate); }
.period-editor .pe-check input { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
.period-editor .pe-date-row.disabled-row { opacity: .5; }
.period-editor .pe-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.period-editor .pe-hint { font-size: .74rem; color: var(--muted); margin-top: 10px; line-height: 1.6; }
