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

:root {
    --bg: #0f151d;
    --panel: #16202b;
    --panel-alt: #1c2836;
    --line: #263241;
    --text: #e7edf3;
    --muted: #8fa1b3;
    --accent: #e8a33d;
    --accent-dark: #c8842a;
    --success: #3ea66b;
    --error: #d9544d;
    --radius: 10px;
}

* { box-sizing: border-box; }

html {
    overflow-x: hidden;
    width: 100%;
}

body {
    margin: 0;
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    width: 100%;
}

.muted { color: var(--muted); font-size: 14px; }

/* ---------- Auth pages ---------- */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.auth-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 36px;
    width: 100%;
    max-width: 380px;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.brand-mark { color: var(--accent); font-size: 22px; }
.auth-card h1 { font-size: 20px; margin: 0; }
.auth-form { display: flex; flex-direction: column; gap: 16px; margin-top: 20px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }

input, select, button {
    font-family: inherit;
    font-size: 15px;
}

input[type=text], input[type=password], input[type=date], input[type=time], input[type=tel], select {
    background: var(--panel-alt);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
    outline: none;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}
input:focus, select:focus, button:focus-visible {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(232, 163, 61, 0.2);
}

button, .btn-link {
    background: var(--accent);
    color: #16202b;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-weight: 600;
    cursor: pointer;
    display: inline-block;
    text-decoration: none;
    text-align: center;
    transition: background .15s ease;
}
button:hover, .btn-link:hover { background: var(--accent-dark); }

.btn-small {
    background: var(--panel-alt);
    color: var(--text);
    border: 1px solid var(--line);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}
.btn-small:hover { border-color: var(--accent); background: var(--panel-alt); }

.btn-danger {
    background: rgba(217, 84, 77, .12);
    color: #f0a29d;
    border: 1px solid rgba(217, 84, 77, .4);
}
.btn-danger:hover { background: rgba(217, 84, 77, .22); border-color: var(--error); }
.btn-danger:disabled { opacity: .6; cursor: default; }

.search-box-wrap { margin-bottom: 14px; }
.search-box-wrap input {
    max-width: 320px;
}

.alert { padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-top: 16px; }
.alert-error { background: rgba(217, 84, 77, .15); color: #f0a29d; border: 1px solid rgba(217,84,77,.4); }
.alert-success { background: rgba(62, 166, 107, .15); color: #9adfb7; border: 1px solid rgba(62,166,107,.4); }
.alert-info { background: rgba(143, 161, 179, .15); color: var(--muted); border: 1px solid var(--line); }

/* ---------- App shell ---------- */
.topbar {
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: nowrap;
}
.topbar-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.topbar-nav { display: flex; gap: 18px; align-items: center; }
.topbar-nav a { color: var(--muted); text-decoration: none; font-size: 14px; padding: 6px 0; }
.topbar-nav a:hover { color: var(--accent); }
.topbar-user { display: flex; align-items: center; gap: 14px; font-size: 14px; color: var(--muted); white-space: nowrap; }
.topbar-user-mobile { display: none; }
.btn-logout {
    color: var(--error);
    text-decoration: none;
    border: 1px solid rgba(217,84,77,.4);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
}
.btn-logout:hover { background: rgba(217,84,77,.1); }

/* دکمه همبرگری - فقط در موبایل نمایش داده می‌شود */
.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 34px;
    height: 34px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0;
    cursor: pointer;
}
.nav-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text);
    margin: 0 auto;
    transition: transform .2s ease, opacity .2s ease;
}
.nav-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle.open span:nth-child(2) { opacity: 0; }
.nav-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

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

.grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}
@media (min-width: 900px) {
    .grid { grid-template-columns: 1fr 1fr; }
    .grid .card:last-child { grid-column: 1 / -1; }
}

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px;
}
.card h2 { margin: 0 0 16px; font-size: 17px; }

.card-header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.card-header-row h2 { margin: 0; }

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 16px;
}
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.full-width { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: center; gap: 14px; }
.form-msg { font-size: 13px; }
.form-msg.ok { color: var(--success); }
.form-msg.err { color: var(--error); }

.inline-filter { display: inline-block; }
.inline-filter input { width: auto; min-width: 150px; }

.driver-warning {
    display: block;
    margin-top: 8px;
    padding: 8px 10px;
    background: rgba(232, 163, 61, .12);
    border: 1px solid rgba(232, 163, 61, .4);
    color: #f0c584;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.7;
}

.time-with-now {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.time-with-now input { flex: 1; min-width: 0; }
.time-with-now .btn-small { white-space: nowrap; }

.jalali-date {
    display: flex;
    gap: 6px;
}
.jalali-date select { min-width: 0; flex: 1; }
.jalali-date .jalali-year { flex: 1.1; }
.jalali-date .jalali-month { flex: 1.3; }
.jalali-date .jalali-day { flex: 0.8; }

.date-with-today {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.date-with-today .jalali-date { flex: 1; }
.date-with-today .btn-small { white-space: nowrap; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
    text-align: right;
    color: var(--muted);
    font-weight: 600;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
tbody tr:hover { background: var(--panel-alt); }
.empty-row { text-align: center; color: var(--muted); padding: 24px !important; }

.badge { padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-active { background: rgba(62,166,107,.15); color: #9adfb7; }
.badge-inactive { background: rgba(217,84,77,.15); color: #f0a29d; }

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.row-actions form { display: inline-block; }

@media (max-width: 560px) {
    .form-grid { grid-template-columns: 1fr; }
}

/* ========================================================
   موبایل: منوی همبرگری + تنظیمات لمسی
   ======================================================== */
@media (max-width: 760px) {
    .nav-toggle { display: flex; }

    .topbar-nav {
        position: absolute;
        top: 100%;
        right: 0;
        left: 0;
        background: var(--panel);
        border-bottom: 1px solid var(--line);
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        max-height: 0;
        overflow: hidden;
        transition: max-height .2s ease;
    }
    .topbar-nav.open { max-height: 400px; }
    .topbar-nav a {
        padding: 14px 20px;
        border-bottom: 1px solid var(--line);
        font-size: 15px;
    }
    .topbar-user-desktop { display: none; }
    .topbar-user-mobile {
        display: flex;
        justify-content: space-between;
        padding: 14px 20px;
    }
    .topbar { position: relative; }
    .topbar-inner { position: relative; }
}

@media (max-width: 480px) {
    .container { padding: 16px 12px 50px; }
    .card { padding: 16px; }
    .auth-card { padding: 26px 20px; }

    /* دکمه‌های اصلی فرم بزرگ‌تر برای لمس راحت‌تر با انگشت (دکمه همبرگر و دکمه‌های کوچک مستثنی هستند) */
    .form-actions > button,
    .auth-form > button,
    .btn-link {
        width: 100%;
        padding: 13px 20px;
    }
    .form-actions { flex-wrap: wrap; }
    .time-with-now .btn-small { width: auto; flex: 0 0 auto; }
    input[type=text], input[type=password], input[type=date],
    input[type=time], input[type=tel], select {
        padding: 12px 14px;
        font-size: 16px; /* جلوگیری از زوم خودکار سافاری روی فرم */
    }
    table { font-size: 13px; }
    thead th, tbody td { padding: 8px; }
}

@media (max-width: 400px) {
    .topbar-inner { padding: 12px 14px; }
    .topbar-brand { font-size: 14px; }
    .brand-mark { font-size: 18px; }
}

/* ========================================================
   تبدیل جدول‌ها به کارت در گوشی (به‌جای اسکرول افقی)
   ======================================================== */
@media (max-width: 700px) {
    .table-wrap { overflow-x: visible; }

    .responsive-table thead { display: none; }

    .responsive-table,
    .responsive-table tbody,
    .responsive-table tr,
    .responsive-table td {
        display: block;
        width: 100%;
    }

    .responsive-table tbody tr {
        margin-bottom: 12px;
        border: 1px solid var(--line);
        border-radius: 10px;
        padding: 4px 12px;
        background: var(--panel-alt);
    }
    .responsive-table tbody tr:last-child { margin-bottom: 0; }

    .responsive-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        padding: 10px 0;
        border-bottom: 1px solid var(--line);
        white-space: normal;
        text-align: left;
        font-size: 14px;
    }
    .responsive-table td:last-child { border-bottom: none; }

    .responsive-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--muted);
        font-size: 12px;
        flex-shrink: 0;
    }
    .responsive-table td:not([data-label])::before { content: none; }

    .responsive-table .empty-row {
        display: block;
        text-align: center;
        border: none;
        background: transparent;
        padding: 20px !important;
    }

    .responsive-table .row-actions { justify-content: flex-start; width: 100%; }
}
