@import url('fonts.css');

:root {
    --navy: #2B3A67;
    --navy-dark: #1E2947;
    --navy-light: #EEF1F8;
    --teal: #17876F;
    --teal-light: #E5F5F1;
    --gold: #C9962C;
    --gold-light: #FBF1DC;
    --red: #C0392B;
    --red-light: #FBEAE8;
    --grey: #6B7280;
    --grey-light: #F4F5F8;
    --border: #E1E4EA;
    --bg: #F6F7F9;
    --card: #FFFFFF;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 1px 3px rgba(30,41,71,.07), 0 1px 2px rgba(30,41,71,.05);
    --shadow-lg: 0 12px 32px rgba(30,41,71,.18);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    background: var(--bg);
    color: #1F2430;
    direction: rtl;
    font-size: 15px;
    line-height: 1.75;
    -webkit-tap-highlight-color: transparent;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
a { color: inherit; text-decoration: none; }
h1,h2,h3 { margin: 0; font-weight: 700; }
input, select, textarea, button { font-family: inherit; font-size: 15px; }
p { margin: 0 0 8px; }

/* ===== Topbar ===== */
.topbar {
    position: sticky; top: 0; z-index: 40;
    background: linear-gradient(135deg, var(--navy), var(--navy-dark));
    color: #fff;
    padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
    display: flex; align-items: center; justify-content: space-between;
    box-shadow: 0 2px 12px rgba(30,41,71,.28);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16.5px; }
.logo-badge {
    width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0;
    background: linear-gradient(135deg, var(--teal), #0F6350);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 16px; box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn {
    background: rgba(255,255,255,.14); border: none; color: #fff;
    width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 15px;
}
.icon-btn:active { background: rgba(255,255,255,.28); }

.container { max-width: 1200px; margin: 0 auto; padding: 16px; }

/* ===== KPI cards ===== */
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
@media (min-width: 720px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1000px) { .kpi-grid { grid-template-columns: repeat(6, 1fr); } }
.kpi-card {
    background: var(--card); border-radius: var(--radius); padding: 14px;
    box-shadow: var(--shadow); border-top: 3px solid var(--navy); cursor: pointer;
    display: flex; flex-direction: column; gap: 6px; transition: transform .12s;
}
.kpi-card:active { transform: scale(.97); }
.kpi-value { font-size: 25px; font-weight: 700; color: var(--navy); }
.kpi-label { font-size: 12px; color: var(--grey); font-weight: 500; }
.kpi-card.c-teal { border-color: var(--teal); } .kpi-card.c-teal .kpi-value { color: var(--teal); }
.kpi-card.c-gold { border-color: var(--gold); } .kpi-card.c-gold .kpi-value { color: var(--gold); }
.kpi-card.c-red { border-color: var(--red); } .kpi-card.c-red .kpi-value { color: var(--red); }
.kpi-card.c-green { border-color: var(--teal); } .kpi-card.c-green .kpi-value { color: var(--teal); }

/* ===== Cards / sections ===== */
.detail-header, .card {
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 16px; margin-bottom: 16px;
}
.section-title { font-size: 14px; font-weight: 700; color: var(--navy); margin: 18px 0 10px; padding-top: 12px; border-top: 1px solid var(--border); }
.section-title:first-of-type, .detail-header > .section-title:first-child { border-top: none; padding-top: 0; margin-top: 0; }

/* ===== Buttons ===== */
.btn, .btn-primary {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: none; border-radius: var(--radius-sm); padding: 10px 16px; font-weight: 600;
    cursor: pointer; font-size: 14px; transition: .15s; white-space: nowrap;
}
.btn-primary { background: var(--navy); color: #fff; width: 100%; padding: 13px; margin-top: 8px; }
.btn-primary:active { background: var(--navy-dark); }
.btn-add { background: var(--teal); color: #fff; }
.btn-add:active { background: #0F6350; }
.btn-outline { background: #fff; color: var(--navy); border: 1.5px solid var(--border); }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: var(--grey-light); color: var(--navy); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===== Badges ===== */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge-green { background: var(--teal-light); color: var(--teal); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-gold { background: var(--gold-light); color: var(--gold); }
.badge-grey { background: var(--grey-light); color: var(--grey); }
.badge-navy { background: var(--navy-light); color: var(--navy); }

/* ===== Forms ===== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.form-grid .full { grid-column: 1 / -1; }
.field { margin-bottom: 14px; position: relative; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--grey); }
.field input[type=text], .field input[type=tel], .field input[type=number], .field input[type=password],
.field select, .field textarea {
    width: 100%; padding: 11px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
    background: #fff; color: #1F2430; outline: none; transition: .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--navy); }
.field textarea { resize: vertical; min-height: 56px; }
.jalali-field input[type=text] { cursor: pointer; padding-left: 62px; background: #fff; }
.today-btn {
    position: absolute; left: 8px; top: 33px;
    background: var(--navy-light); color: var(--navy); border: none; border-radius: 6px;
    font-size: 11px; padding: 5px 9px; cursor: pointer; font-weight: 600;
}

/* ===== Jalali datepicker popup (jalali-datepicker.js) ===== */
.jdp-popup {
    position: absolute; z-index: 100; top: calc(100% + 6px); right: 0;
    background: #fff; border-radius: 12px; box-shadow: var(--shadow-lg);
    padding: 12px; width: 272px; display: none; border: 1px solid var(--border);
}
.jdp-popup.open { display: block; }
.jdp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.jdp-head button { background: var(--grey-light); border: none; width: 28px; height: 28px; border-radius: 8px; cursor: pointer; font-size: 15px; color: var(--navy); }
.jdp-title { font-weight: 700; font-size: 13.5px; }
.jdp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.jdp-dow .dow { font-size: 10.5px; color: var(--grey); font-weight: 600; padding: 4px 0; }
.jdp-days .day { padding: 7px 0; border-radius: 8px; cursor: pointer; font-size: 12.5px; }
.jdp-days .day:hover { background: var(--navy-light); }
.jdp-days .day.today { color: var(--teal); font-weight: 700; }
.jdp-days .day.selected { background: var(--navy); color: #fff; }
.jdp-days .day.empty { cursor: default; }
.jdp-footer { display: flex; gap: 8px; margin-top: 10px; }
.jdp-today-btn, .jdp-clear-btn {
    flex: 1; padding: 7px; border: none; border-radius: 8px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.jdp-today-btn { background: var(--teal); color: #fff; }
.jdp-clear-btn { background: var(--grey-light); color: var(--grey); }

/* ===== Toolbar / table ===== */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.search-box { flex: 1; min-width: 200px; position: relative; }
.search-box input { width: 100%; padding: 11px 38px 11px 12px; border-radius: var(--radius-sm); border: 1.5px solid var(--border); background: #fff; }
.search-box .icon { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--grey); font-size: 14px; }

.chip-filters { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
    padding: 6px 14px; border-radius: 999px; background: #fff; border: 1.5px solid var(--border);
    font-size: 12.5px; font-weight: 600; color: var(--grey); cursor: pointer;
}
.chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }

.scroll-hint { font-size: 11.5px; color: var(--grey); text-align: center; margin: 4px 0 8px; }

.table-wrap { position: relative; overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); background: #fff; -webkit-overflow-scrolling: touch; }
table.data-table { border-collapse: collapse; width: 100%; min-width: 1500px; }
table.data-table th, table.data-table td {
    padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--grey-light); white-space: nowrap; font-size: 13px;
}
table.data-table thead tr:first-child th {
    background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 5; font-weight: 600; cursor: pointer; user-select: none;
}
table.data-table thead tr:first-child th.sorted { background: var(--navy-dark); }
.sort-arrow { font-size: 9px; opacity: .75; margin-inline-start: 4px; }
table.data-table .filter-row th { background: var(--grey-light); position: sticky; top: 37px; z-index: 4; cursor: default; padding: 6px 8px; }
table.data-table .filter-row input, table.data-table .filter-row select {
    width: 100%; padding: 6px 7px; border: 1px solid var(--border); border-radius: 6px; font-size: 11.5px; background: #fff;
}
table.data-table tbody tr.row-clickable { cursor: pointer; }
table.data-table tbody tr:nth-child(even) { background: var(--grey-light); }
table.data-table tbody tr:hover { background: var(--navy-light); }
table.data-table td .cell-name { font-weight: 700; }
td.cell-name { font-weight: 700; }
table.data-table td a.domain-link { color: var(--teal); font-weight: 600; }
table.data-table td a.domain-link:hover { text-decoration: underline; }
.no-results { text-align: center; padding: 50px 20px; color: var(--grey); font-size: 13.5px; }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(20,25,40,.55); backdrop-filter: blur(2px);
    display: none; align-items: flex-end; justify-content: center; z-index: 200;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: #fff; border-radius: 18px 18px 0 0; width: 100%; max-width: 600px;
    max-height: 92vh; overflow-y: auto; padding: 18px; box-shadow: var(--shadow-lg);
}
@media (min-width: 720px) {
    .modal-overlay { align-items: center; }
    .modal-box { border-radius: 18px; max-height: 88vh; }
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-title { font-size: 16px; font-weight: 700; color: var(--navy); }
.modal-close { background: var(--grey-light); border: none; width: 32px; height: 32px; border-radius: 9px; cursor: pointer; font-size: 15px; }
.modal-footer { display: flex; gap: 10px; margin-top: 14px; }
.modal-footer .btn { flex: 1; justify-content: center; padding: 12px; }

/* ===== Auth (login / install) ===== */
.auth-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(160deg, var(--navy), var(--navy-dark)); }
.auth-card { background: #fff; border-radius: 20px; padding: 34px 26px; width: 100%; max-width: 380px; box-shadow: var(--shadow-lg); text-align: center; }
.auth-logo { display: flex; justify-content: center; margin-bottom: 14px; }
.auth-logo .logo-badge { width: 60px; height: 60px; border-radius: 16px; font-size: 26px; }
.auth-title { font-size: 19px; margin-bottom: 4px; color: var(--navy); }
.auth-sub { color: var(--grey); font-size: 13px; margin-bottom: 20px; }
.auth-form { text-align: right; }
.auth-form label { display: block; font-size: 12.5px; font-weight: 600; color: var(--grey); margin: 12px 0 6px; }
.auth-form input {
    width: 100%; padding: 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
    background: #fff; outline: none;
}
.auth-form input:focus { border-color: var(--navy); }
.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 12px; text-align: right; }
.alert-error { background: var(--red-light); color: var(--red); }
.alert-success { background: var(--teal-light); color: var(--teal); }

/* ===== Detail page ===== */
.back-link { display: inline-block; margin-bottom: 12px; font-size: 13px; color: var(--navy); font-weight: 600; }
.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 20px; margin-bottom: 4px; }
@media (max-width: 560px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-item { padding: 9px 0; border-bottom: 1px solid var(--grey-light); }
.detail-item .k { font-size: 11.5px; color: var(--grey); margin-bottom: 3px; }
.detail-item .v { font-weight: 600; font-size: 13.5px; }

/* ===== Toast ===== */
.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: var(--navy-dark); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 13px;
    box-shadow: var(--shadow-lg); z-index: 300; opacity: 0; pointer-events: none; transition: .25s;
}
.toast.show { opacity: 1; bottom: 34px; }
