/* ============================================================
   DataSync — shared design system
   Modern, RTL-first, light/dark aware.
   ============================================================ */

/* ---- Design tokens ---------------------------------------- */
:root {
    color-scheme: light dark;

    --font: "Vazirmatn", ui-sans-serif, system-ui, -apple-system,
            "Segoe UI", Tahoma, sans-serif;

    /* Light theme */
    --bg:        #eef2f7;
    --bg-accent: #dbe6f3;
    --surface:   #ffffff;
    --surface-2: #f6f9fc;
    --text:      #0f1c2e;
    --muted:     #64748b;
    --border:    #e2e8f0;
    --brand:     #0b5cab;
    --brand-600: #0a4f93;
    --brand-700: #073e74;
    --brand-ink: #ffffff;
    --ring:      rgba(11, 92, 171, 0.28);
    --unread:    #16a34a;
    --danger:    #b42318;
    --danger-bg: #fef3f2;
    --shadow:    0 10px 30px -12px rgba(15, 28, 46, 0.25);
    --shadow-sm: 0 1px 2px rgba(15, 28, 46, 0.06),
                 0 6px 20px -14px rgba(15, 28, 46, 0.35);
    --radius:    16px;
    --radius-sm: 10px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:        #0b1220;
        --bg-accent: #0f1b30;
        --surface:   #131d2f;
        --surface-2: #182338;
        --text:      #e8eef7;
        --muted:     #93a4bd;
        --border:    #26344b;
        --brand:     #3d8be0;
        --brand-600: #5aa0ee;
        --brand-700: #7bb4f3;
        --brand-ink: #06101f;
        --ring:      rgba(61, 139, 224, 0.35);
        --unread:    #22c55e;
        --danger:    #ff6b5e;
        --danger-bg: #2a1614;
        --shadow:    0 20px 40px -18px rgba(0, 0, 0, 0.7);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4),
                     0 8px 24px -16px rgba(0, 0, 0, 0.8);
    }
}

/* ---- Base ------------------------------------------------- */
* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    line-height: 1.6;
}

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

/* ---- Buttons ---------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1;
    padding: 0 18px;
    height: 44px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: transform .06s ease, background .15s ease,
                box-shadow .15s ease, border-color .15s ease;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
    width: 100%;
    background: linear-gradient(180deg, var(--brand), var(--brand-600));
    color: var(--brand-ink);
    box-shadow: 0 8px 20px -10px var(--ring);
}
.btn-primary:hover { background: linear-gradient(180deg, var(--brand-600), var(--brand-700)); }

.btn-ghost {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
    box-shadow: var(--shadow-sm);
    height: 40px;
    padding: 0 14px;
    font-weight: 500;
}
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); }

.icon { width: 18px; height: 18px; flex: 0 0 auto; }

/* ============================================================
   Login
   ============================================================ */
.auth-wrap {
    min-height: 100%;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(1200px 600px at 100% -10%, var(--bg-accent), transparent 60%),
        radial-gradient(900px 500px at -10% 110%, var(--bg-accent), transparent 55%),
        var(--bg);
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 36px 32px 32px;
}

.brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    margin-bottom: 26px;
    text-align: center;
}
.brand-logo {
    width: 60px;
    height: 60px;
    display: grid;
    place-items: center;
    border-radius: 18px;
    color: var(--brand-ink);
    background: linear-gradient(160deg, var(--brand), var(--brand-700));
    box-shadow: 0 12px 24px -12px var(--ring);
}
.brand-logo .icon { width: 30px; height: 30px; }
.brand h1 { font-size: 1.28rem; font-weight: 700; margin: 0; }
.brand p  { margin: 0; color: var(--muted); font-size: 0.9rem; }

.field { margin-bottom: 16px; }
.field label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--muted);
    margin-bottom: 8px;
}
.input-shell {
    position: relative;
    display: flex;
    align-items: center;
}
.input-shell .icon {
    position: absolute;
    inset-inline-start: 14px;
    color: var(--muted);
    pointer-events: none;
}
.input {
    width: 100%;
    height: 48px;
    font-family: inherit;
    font-size: 1rem;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding-inline: 44px 14px;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.input::placeholder { color: var(--muted); opacity: .8; }
.input:focus {
    outline: none;
    background: var(--surface);
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--ring);
}

.alert {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    color: var(--danger);
    background: var(--danger-bg);
    border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 16px;
}

/* ============================================================
   Listing
   ============================================================ */
.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: color-mix(in srgb, var(--surface) 85%, transparent);
    backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--border);
}
.app-header .bar {
    max-width: 1080px;
    margin: 0 auto;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
}
.app-header .logo {
    width: 40px; height: 40px;
    display: grid; place-items: center;
    border-radius: 12px;
    color: var(--brand-ink);
    background: linear-gradient(160deg, var(--brand), var(--brand-700));
    flex: 0 0 auto;
}
.app-header .logo .icon { width: 22px; height: 22px; }
.app-header h1 { font-size: 1.05rem; font-weight: 700; margin: 0; }
.app-header .sub { font-size: 0.78rem; color: var(--muted); }
.spacer { flex: 1; }

.refresh-status {
    font-size: 0.78rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Floating refresh button (bottom-inline-end) */
.fab {
    position: fixed;
    bottom: 24px;
    right: 24px;   /* physical bottom-right, regardless of RTL */
    z-index: 40;
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    border: none;
    border-radius: 50%;
    color: var(--brand-ink);
    background: linear-gradient(160deg, var(--brand), var(--brand-700));
    box-shadow: 0 14px 30px -10px var(--ring), 0 4px 10px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: transform .12s ease, box-shadow .15s ease;
}
.fab:hover { transform: translateY(-2px); box-shadow: 0 18px 36px -10px var(--ring); }
.fab:active { transform: translateY(0); }
.fab .icon { width: 24px; height: 24px; }

/* Logs button — turns amber with a dot when there are unread entries */
.btn-logs { position: relative; }
.btn-logs.has-unread {
    color: #d97706;
    border-color: color-mix(in srgb, #f59e0b 55%, var(--border));
    background: color-mix(in srgb, #f59e0b 14%, var(--surface));
}
.btn-logs.has-unread::after {
    content: "";
    position: absolute;
    top: -3px;
    inset-inline-start: -3px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #f59e0b;
    box-shadow: 0 0 0 2px var(--surface);
}

/* ---- Logs page -------------------------------------------- */
.log-list { display: flex; flex-direction: column; gap: 10px; }
.log-entry {
    background: var(--surface);
    border: 1px solid var(--border);
    border-inline-start: 3px solid var(--muted);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    padding: 12px 14px;
}
.log-entry.log-error { border-inline-start-color: var(--danger); }
.log-entry.log-warning { border-inline-start-color: #f59e0b; }
.log-entry.log-info { border-inline-start-color: var(--brand); }
.log-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.log-level {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: .04em;
    padding: 2px 8px;
    border-radius: 999px;
    color: var(--muted);
    background: var(--surface-2);
}
.log-error .log-level { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }
.log-warning .log-level { color: #b45309; background: color-mix(in srgb, #f59e0b 16%, transparent); }
.log-ts { font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.log-msg {
    margin: 0;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
}

.container { max-width: 1080px; margin: 0 auto; padding: 24px 20px 48px; }

/* ---- Filter bar ------------------------------------------- */
.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 14px;
    margin-bottom: 18px;
}
.filter { display: flex; flex-direction: column; gap: 7px; }
.filter > label {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--muted);
    padding-inline-start: 4px;
    text-align: right;
}
.filter-search { flex: 1 1 260px; min-width: 200px; }
.filter-actions { flex-direction: row; align-items: center; gap: 10px; }

.btn-inline { width: auto; height: 46px; }

/* ---- Custom date picker ----------------------------------- */
.datepicker { position: relative; }
.date-field {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    height: 46px;
    min-width: 190px;
    font-family: inherit;
    font-size: 0.92rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 14px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.date-field .icon { color: var(--muted); flex: 0 0 auto; }
.date-field:hover { border-color: var(--brand); }
.datepicker.open .date-field {
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--ring);
}
.dp-placeholder { color: var(--muted); }
.datepicker.has-value .dp-placeholder { display: none; }
.datepicker:not(.has-value) .dp-value { display: none; }
.dp-value { unicode-bidi: plaintext; font-variant-numeric: tabular-nums; }
/* Push the trigger's text (value/placeholder) to the right; icon stays left */
.date-field .dp-value,
.date-field .dp-placeholder { flex: 1; text-align: right; }

.dp-popover {
    position: absolute;
    z-index: 30;
    top: calc(100% + 8px);
    right: 0;   /* anchor to the field's right edge; opens leftward, stays on-screen */
    width: 300px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
}
.dp-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.dp-title { text-align: center; font-size: 0.95rem; font-weight: 600; }
.dp-nav {
    width: 34px; height: 34px;
    display: grid; place-items: center;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: border-color .15s ease, color .15s ease;
}
.dp-nav:hover { border-color: var(--brand); color: var(--brand); }
.dp-nav .icon { width: 18px; height: 18px; }

.dp-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-auto-rows: 36px;   /* uniform rows — avoids the partial first week stretching */
    align-content: start;
    gap: 2px;
}
.dp-wd {
    text-align: center;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--muted);
    padding-bottom: 6px;
}
.dp-cell {
    height: 36px;
    display: grid;
    place-items: center;
    border: none;
    background: transparent;
    border-radius: 9px;
    font-family: inherit;
    font-size: 0.88rem;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    cursor: pointer;
    transition: background .12s ease, color .12s ease;
}
.dp-cell.empty { cursor: default; }
.dp-cell:not(.empty):hover { background: var(--surface-2); }
.dp-cell.today { box-shadow: inset 0 0 0 1px var(--border); }
.dp-cell.selected {
    background: var(--brand);
    color: var(--brand-ink);
    font-weight: 600;
}
.dp-cell.selected:hover { background: var(--brand-600); }

.dp-foot {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}
.dp-link {
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--brand);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
}
.dp-link:hover { background: var(--surface-2); }

.search-shell { position: relative; }
.search-shell .icon {
    position: absolute;
    inset-inline-start: 14px;
    top: 50%; transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}
.search {
    width: 100%;
    height: 46px;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding-inline: 44px 14px;
    box-shadow: var(--shadow-sm);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.search:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--ring);
}

.table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.table-scroll { overflow-x: auto; }

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}
table.data thead th {
    position: sticky;
    top: 0;
    text-align: center;
    font-weight: 600;
    font-size: 0.78rem;
    letter-spacing: .02em;
    text-transform: uppercase;
    color: var(--muted);
    background: var(--surface-2);
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.data tbody td {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    text-align: center;
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background .12s ease; }
table.data tbody tr:hover { background: var(--surface-2); }

.num {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    color: var(--muted);
    unicode-bidi: plaintext;
}
.chip {
    display: inline-block;
    font-size: 0.82rem;
    font-weight: 500;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 3px 9px;
    unicode-bidi: plaintext;
    direction: ltr;
}
/* SMS text: RTL and right-aligned; all other columns centered.
   Higher specificity than `table.data tbody td { text-align: center }`. */
table.data thead th.th-body,
table.data tbody td.body-cell { text-align: right; }
.body-cell { max-width: 420px; line-height: 1.7; direction: rtl; }
.date-cell { color: var(--muted); white-space: nowrap; unicode-bidi: plaintext; }

mark {
    background: #ffe08a;
    color: #3a2a00;
    border-radius: 4px;
    padding: 0 2px;
    font-weight: 600;
}

/* ---- Read / unread --------------------------------------- */
.unread-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--unread);
    background: color-mix(in srgb, var(--unread) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--unread) 28%, transparent);
    padding: 5px 11px;
    border-radius: 999px;
    white-space: nowrap;
}

.th-read { width: 1%; white-space: nowrap; }

/* Status indicator: a plain clickable circle — no button chrome, no label */
.read-toggle {
    display: inline-grid;
    place-items: center;
    padding: 6px;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
}
.read-toggle:hover { background: var(--surface-2); }
.read-toggle:disabled { opacity: .5; cursor: default; }
.read-dot {
    width: 15px;
    height: 15px;
    border-radius: 50%;
    box-sizing: border-box;
}

/* Unread: filled green circle + emphasised row */
tr[data-read="0"] { background: color-mix(in srgb, var(--unread) 6%, transparent); }
/* Keep unread green on hover (stronger tint), distinct from the grey hover of read rows */
table.data tbody tr[data-read="0"]:hover { background: color-mix(in srgb, var(--unread) 14%, transparent); }
tr[data-read="0"] .body-cell { font-weight: 600; }
tr[data-read="0"] .read-dot { background: var(--unread); }

/* Read: outlined circle */
tr[data-read="1"] .read-dot { background: transparent; border: 2px solid var(--muted); opacity: .8; }

/* ---- Results bar + pagination ----------------------------- */
.results-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 16px;
    padding: 0 2px;
}
.results-count { font-size: 0.86rem; color: var(--muted); }
.results-count strong { color: var(--text); font-weight: 600; }

.pagination { display: flex; align-items: center; gap: 6px; }
.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.88rem;
    font-weight: 500;
    box-shadow: var(--shadow-sm);
    transition: border-color .15s ease, color .15s ease;
}
.page-btn:hover { border-color: var(--brand); color: var(--brand); }
.page-btn.disabled { opacity: .45; pointer-events: none; }
.page-info { font-size: 0.85rem; color: var(--muted); padding: 0 8px; }

.empty {
    padding: 64px 24px;
    text-align: center;
    color: var(--muted);
}
.empty .icon { width: 44px; height: 44px; margin-bottom: 12px; opacity: .6; }
.empty h2 { margin: 0 0 4px; font-size: 1.05rem; color: var(--text); font-weight: 600; }
.empty p { margin: 0; font-size: 0.9rem; }

/* ---- Responsive: table -> cards on small screens ---------- */
@media (max-width: 640px) {
    .app-header .sub { display: none; }
    table.data thead { display: none; }
    table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
    table.data tbody tr {
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        background: var(--surface);
        margin: 12px;
        padding: 6px 4px;
    }
    table.data tbody tr:hover { background: var(--surface); }
    table.data tbody td {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 16px;
        border: none;
        padding: 9px 14px;
    }
    table.data tbody td::before {
        content: attr(data-label);
        font-size: 0.78rem;
        font-weight: 600;
        color: var(--muted);
        flex: 0 0 auto;
    }
    .body-cell { max-width: none; text-align: start; }
}
