/* SpinConnect app shell — dark, phone-first, RTL aware (logical properties). */
:root {
    --bg: #0f172a;
    --card: #1e293b;
    --card2: #172033;
    --line: #334155;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --accent: #2563eb;
    --won: #22c55e;
    --lost: #ef4444;
    --open: #38bdf8;
    --cash: #a78bfa;
    --refund: #94a3b8;
    --orange: #f59e0b;
    --yellow: #facc15;
    --rail: 232px;
    --tabbar: 64px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body.app {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Tahoma, Arial, sans-serif;
}
[dir="rtl"] body.app { font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif; }
body.app a { color: inherit; }
body.app [hidden] { display: none !important; }
.ico { width: 20px; height: 20px; flex: 0 0 auto; }
.num, .money { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }

/* layout */
.app-wrap { min-height: 100vh; }
body.has-nav .app-wrap { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }
.app-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px 8px;
    padding-top: calc(12px + env(safe-area-inset-top));
}
.app-top h1 { font-size: 20px; margin: 0; }
.app-sub { color: var(--muted); font-size: 13px; }
.app-top-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.app-hidden { display: none !important; }
.app-main { padding: 4px 14px 30px; max-width: 1180px; margin: 0 auto; }

/* buttons */
.app-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 40px;
    padding: 0 14px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}
.app-btn-ghost { background: transparent; font-size: 13px; min-height: 36px; padding: 0 10px; }
.app-btn-primary { background: var(--accent); border-color: #3b82f6; }
.app-btn-green { background: #14532d; border-color: #166534; }
.app-btn-red { background: #7f1d1d; border-color: #991b1b; }
.app-btn:disabled { opacity: .5; cursor: not-allowed; }

/* rail (PC) */
.app-rail { display: none; }
@media (min-width: 900px) {
    body.has-nav .app-rail {
        display: flex;
        flex-direction: column;
        position: fixed;
        inset-block: 0;
        inset-inline-start: 0;
        width: var(--rail);
        background: #0b1222;
        border-inline-end: 1px solid var(--line);
        padding: 16px 10px;
        overflow-y: auto;
        z-index: 20;
    }
    body.has-nav .app-wrap { margin-inline-start: var(--rail); padding-bottom: 0; }
    body.has-nav .app-tabbar, body.has-nav .app-sheet { display: none !important; }
    .app-only-phone { display: none !important; }
    .app-only-phone.app-show { display: inline-flex !important; }
    .app-top { padding: 18px 24px 10px; }
    .app-main { padding: 4px 24px 40px; }
}
.app-brand { font-size: 19px; font-weight: 800; padding: 4px 10px 16px; letter-spacing: .01em; }
.app-brand span { color: #60a5fa; }
.app-rail-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.app-rail-nav a, .app-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 9px;
    text-decoration: none;
    color: var(--muted);
    font-weight: 600;
    font-size: 14px;
}
.app-rail-nav a:hover, .app-link:hover { background: var(--card); color: var(--text); }
.app-rail-nav a.on { background: var(--accent); color: #fff; }
.app-rail-foot { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.app-user { padding: 4px 10px 8px; display: flex; flex-direction: column; }
.app-user small { color: var(--muted); }

/* tab bar (phone) */
.app-tabbar {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    background: rgba(11, 18, 34, .98);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
}
.app-tabbar a, .app-tabbar button {
    flex: 1;
    min-height: var(--tabbar);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: none;
    border: 0;
    color: var(--muted);
    font: inherit;
    font-size: 11px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    padding: 0 2px;
    text-align: center;
}
.app-tabbar .ico { width: 22px; height: 22px; }
.app-tabbar .on { color: #60a5fa; }
.app-sheet { position: fixed; inset: 0; z-index: 29; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-end; }
.app-sheet-card {
    width: 100%;
    background: var(--card2);
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    padding: 14px 12px calc(var(--tabbar) + 14px + env(safe-area-inset-bottom));
}
.app-sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.app-sheet-grid a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 4px;
    border-radius: 12px;
    background: var(--card);
    border: 1px solid var(--line);
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
}
.app-sheet-grid a.on { border-color: #3b82f6; }

/* shared building blocks */
.app-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.app-chips::-webkit-scrollbar { display: none; }
.app-chips a, .app-chips button {
    flex: 0 0 auto;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}
.app-chips .on { background: var(--text); color: var(--bg); }
.app-section { margin: 18px 0 8px; }
.app-section h2 { font-size: 16px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.app-section h2 small { color: var(--muted); font-weight: 500; font-size: 13px; }
.app-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.app-muted { color: var(--muted); }
.app-flash { border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-weight: 600; }
.app-flash.ok { background: rgba(34, 197, 94, .15); color: #bbf7d0; border: 1px solid rgba(34, 197, 94, .4); }
.app-flash.err { background: rgba(239, 68, 68, .15); color: #fecaca; border: 1px solid rgba(239, 68, 68, .45); }
.pos { color: var(--won); }
.neg { color: var(--lost); }

/* KPI cards */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi {
    display: block;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 10px 12px;
    text-decoration: none;
}
.kpi small { display: block; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
[dir="rtl"] .kpi small { text-transform: none; letter-spacing: 0; }
.kpi b { display: block; font-size: 21px; margin-top: 2px; direction: ltr; unicode-bidi: isolate; text-align: start; font-variant-numeric: tabular-nums; }
[dir="rtl"] .kpi b { text-align: right; }
.kpi > span { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi > span .money { color: #cbd5e1; font-weight: 600; }
.kpi > span .money.neg { color: var(--lost); }
.kpi.big { grid-column: span 2; background: linear-gradient(135deg, #1e3a8a, #1e293b); border-color: #1d4ed8; }
.kpi.big b { font-size: 28px; }
.kpi .na { color: var(--muted); }

/* forms */
.app-form { display: grid; gap: 10px; }
.app-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.app-form input[type=text], .app-form input[type=password], .app-form input[type=number], .app-form input[type=search], .app-form input[type=date], .app-form select, .app-form textarea {
    width: 100%;
    min-height: 42px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--text);
    font: inherit;
    padding: 0 12px;
    color-scheme: dark;
}
.app-form textarea { padding: 10px 12px; }
.app-form .row2 { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 700px) { .app-form .row2 { grid-template-columns: 1fr 1fr; } }
.app-checks { display: flex; flex-wrap: wrap; gap: 6px; }
.app-check {
    display: inline-flex !important;
    grid-auto-flow: column;
    align-items: center;
    gap: 6px !important;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--bg);
    color: var(--text) !important;
    font-weight: 500 !important;
    cursor: pointer;
}
.app-check input { width: 16px; height: 16px; accent-color: #3b82f6; margin: 0; }
.app-form-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* section sub-pages (tab row under the title) */
.app-subtabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    margin: 0 0 14px;
    padding: 4px;
    background: var(--card2);
    border: 1px solid var(--line);
    border-radius: 12px;
    scrollbar-width: none;
}
.app-subtabs::-webkit-scrollbar { display: none; }
.app-subtabs a {
    flex: 0 0 auto;
    padding: 8px 12px;
    border-radius: 9px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}
.app-subtabs a:hover { color: var(--text); }
.app-subtabs a.on { background: var(--accent); color: #fff; }

/* period bar */
.app-period { margin-bottom: 14px; }
.app-period .app-chips { margin-bottom: 6px; }
.app-period-custom { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; margin-bottom: 6px; }
.app-period-custom label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; font-weight: 600; }
.app-period-custom input { min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); padding: 0 10px; font: inherit; color-scheme: dark; }
.app-period-note { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; color: var(--muted); font-size: 13px; }
.app-period-note .app-btn { margin-inline-start: auto; }

/* generic row list (phone + PC): .app-rows > .app-row { .r-main + .r-side } */
.app-rows { display: grid; gap: 6px; }
.app-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    text-decoration: none;
}
a.app-row:hover { border-color: #3b82f6; }
.app-row .r-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-row .r-main b { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-row .r-main small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.app-row .r-side { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; flex: 0 0 auto; }
.app-row .r-side b { font-size: 16px; direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.app-pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.app-pill.ok { color: #bbf7d0; border-color: rgba(34, 197, 94, .5); }
.app-pill.warn { color: #fde68a; border-color: rgba(245, 158, 11, .55); }
.app-pill.bad { color: #fecaca; border-color: rgba(239, 68, 68, .5); }
.app-pill.info { color: #bae6fd; border-color: rgba(56, 189, 248, .5); }
.app-empty { text-align: center; color: var(--muted); padding: 28px 10px; background: var(--card2); border: 1px dashed var(--line); border-radius: 12px; }
.app-more { display: block; text-align: center; margin: 12px auto 0; max-width: 260px; }
.app-note { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }
.app-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); flex: 0 0 auto; }
.app-dot.on { background: var(--won); box-shadow: 0 0 0 3px rgba(34, 197, 94, .2); }
.app-dot.warn { background: var(--orange); }
.app-dot.bad { background: var(--lost); }

/* expandable row: <details class="app-row"><summary>r-main + r-side</summary> …details… </details> */
details.app-row { display: block; }
details.app-row > summary { display: flex; align-items: center; gap: 10px; cursor: pointer; list-style: none; }
details.app-row > summary::-webkit-details-marker { display: none; }
details.app-row[open] { border-color: #3b82f6; }
details.app-row > :not(summary) { margin-top: 10px; }
.recon-lines { display: grid; gap: 2px; margin: 10px 0 0; }
.recon-lines > div { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.recon-lines dt { color: var(--muted); }
.recon-lines dd { margin: 0; direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.recon-lines .sum dt, .recon-lines .sum dd { color: var(--text); font-weight: 700; }
