/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --primary: #1e40af;
    --primary-dark: #1e3a8a;
    --primary-light: #3b82f6;
    --success: #059669;
    --danger: #dc2626;
    --warning: #d97706;
    --info: #0284c7;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --sidebar-w: 260px;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
}
html { font-size: 15px; }
body {
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    direction: rtl;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ===== Offline Banner ===== */
.offline-banner {
    position: fixed; top: 0; left: 0; right: 0; z-index: 9999;
    background: var(--danger); color: #fff; text-align: center;
    padding: 10px; font-size: .9rem; font-weight: 500;
}
.offline-banner.hidden { display: none; }

/* ===== Sidebar ===== */
.sidebar {
    position: fixed; top: 0; right: 0; bottom: 0; width: var(--sidebar-w);
    background: linear-gradient(180deg, #1e3a8a 0%, #1e40af 100%);
    color: #fff; z-index: 1000; display: flex; flex-direction: column;
    transition: transform .3s ease;
}
.sidebar-header {
    padding: 1.25rem; display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,.15);
}
.logo { font-size: 1.15rem; font-weight: 700; }
.sidebar-close { display: none; background: none; border: none; color: #fff; font-size: 1.4rem; cursor: pointer; }
.nav-menu { list-style: none; flex: 1; overflow-y: auto; padding: .75rem 0; }
.nav-menu a {
    display: flex; align-items: center; gap: .75rem;
    padding: .7rem 1.25rem; color: rgba(255,255,255,.85);
    transition: background .15s, color .15s; text-decoration: none;
}
.nav-menu a:hover, .nav-menu a.active {
    background: rgba(255,255,255,.12); color: #fff;
}
.nav-menu .icon { font-size: 1.2rem; width: 1.5rem; text-align: center; }
.sidebar-footer {
    padding: 1rem 1.25rem; border-top: 1px solid rgba(255,255,255,.15);
}
.user-info strong { display: block; font-size: .95rem; }
.user-info small { opacity: .7; font-size: .8rem; }
.btn-logout {
    display: inline-block; margin-top: .5rem; padding: .35rem .8rem;
    background: rgba(255,255,255,.15); border-radius: 6px; color: #fff; font-size: .85rem;
}
.btn-logout:hover { background: rgba(255,255,255,.25); text-decoration: none; }

.overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 999;
}

/* ===== Main ===== */
.main-content {
    margin-right: var(--sidebar-w); min-height: 100vh;
    transition: margin .3s;
}
.main-content.full-width { margin-right: 0; }

.topbar {
    background: var(--card); padding: .85rem 1.5rem;
    display: flex; align-items: center; gap: 1rem;
    box-shadow: var(--shadow); position: sticky; top: 0; z-index: 50;
}
.menu-toggle {
    display: none; background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text);
}
.page-title { font-size: 1.15rem; font-weight: 700; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: .75rem; }
.net-status { font-size: .8rem; font-weight: 500; }
.net-status.online { color: var(--success); }
.net-status.offline { color: var(--danger); }

.content-wrapper { padding: 1.5rem; max-width: 1400px; }

/* ===== Cards & Stats ===== */
.stats-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem; margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--card); border-radius: var(--radius); padding: 1.25rem;
    box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .35rem;
}
.stat-card .stat-label { font-size: .85rem; color: var(--text-muted); }
.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.warning .stat-value { color: var(--warning); }

.card {
    background: var(--card); border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 1.5rem; overflow: hidden;
}
.card-header {
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .75rem;
}
.card-header h2 { font-size: 1.05rem; font-weight: 600; }
.card-body { padding: 1.25rem; }

/* ===== Tables ===== */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .7rem 1rem; text-align: right; border-bottom: 1px solid var(--border); }
th { background: #f8fafc; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
tr:hover td { background: #f8fafc; }
.badge {
    display: inline-block; padding: .2rem .55rem; border-radius: 20px;
    font-size: .75rem; font-weight: 500;
}
.badge-in { background: #dbeafe; color: #1e40af; }
.badge-out { background: #d1fae5; color: #065f46; }
.badge-missed { background: #fee2e2; color: #991b1b; }
.badge-internal { background: #f3e8ff; color: #6b21a8; }

/* ===== Forms ===== */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: .35rem; font-weight: 500; font-size: .9rem; }
.form-control {
    width: 100%; padding: .65rem .9rem; border: 1px solid var(--border);
    border-radius: 8px; font-family: inherit; font-size: .95rem;
    transition: border-color .15s, box-shadow .15s; background: #fff;
}
.form-control:focus {
    outline: none; border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(59,130,246,.2);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; gap: .75rem; margin-top: 1.25rem; flex-wrap: wrap; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .6rem 1.15rem; border: none; border-radius: 8px;
    font-family: inherit; font-size: .9rem; font-weight: 500;
    cursor: pointer; transition: background .15s, transform .1s;
    text-decoration: none; color: #fff;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; color: #fff; }
.btn-success { background: var(--success); }
.btn-success:hover { background: #047857; text-decoration: none; color: #fff; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; text-decoration: none; color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline {
    background: transparent; border: 1px solid var(--border); color: var(--text);
}
.btn-outline:hover { background: #f1f5f9; text-decoration: none; }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ===== Alerts ===== */
.alert {
    padding: .85rem 1.15rem; border-radius: 8px; margin-bottom: 1rem;
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.alert-success { background: #d1fae5; color: #065f46; }
.alert-error, .alert-danger { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-info { background: #e0f2fe; color: #075985; }
.alert-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; opacity: .6; }

/* ===== Login Page ===== */
.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
    padding: 1.5rem;
}
.login-box {
    background: #fff; border-radius: 16px; padding: 2.5rem 2rem;
    width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.login-box h1 { text-align: center; margin-bottom: .35rem; font-size: 1.4rem; color: var(--primary); }
.login-box .subtitle { text-align: center; color: var(--text-muted); margin-bottom: 1.75rem; font-size: .9rem; }

/* ===== Dial Pad ===== */
.dial-pad {
    max-width: 320px; margin: 0 auto; text-align: center;
}
.dial-display {
    font-size: 1.6rem; letter-spacing: 2px; padding: 1rem;
    border: 2px solid var(--border); border-radius: 12px; margin-bottom: 1rem;
    min-height: 3.2rem; direction: ltr; text-align: center; font-weight: 600;
}
.dial-keys {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem;
}
.dial-key {
    aspect-ratio: 1; border: none; border-radius: 50%;
    background: #f1f5f9; font-size: 1.4rem; font-weight: 600;
    cursor: pointer; transition: background .15s; font-family: inherit;
}
.dial-key:hover { background: #e2e8f0; }
.dial-key:active { background: var(--primary-light); color: #fff; }
.dial-actions { margin-top: 1.25rem; display: flex; gap: .75rem; justify-content: center; }

/* ===== Empty State ===== */
.empty-state {
    text-align: center; padding: 3rem 1rem; color: var(--text-muted);
}
.empty-state .icon { font-size: 3rem; margin-bottom: .75rem; opacity: .5; }

/* ===== Pagination ===== */
.pagination {
    display: flex; gap: .4rem; justify-content: center; margin-top: 1.25rem; flex-wrap: wrap;
}
.pagination a, .pagination span {
    padding: .4rem .75rem; border-radius: 6px; border: 1px solid var(--border);
    font-size: .85rem; color: var(--text);
}
.pagination a:hover { background: #f1f5f9; text-decoration: none; }
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== Search & Filters ===== */
.filters {
    display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin-bottom: 1rem;
}
.filters .form-group { margin-bottom: 0; flex: 1; min-width: 140px; }

/* ===== Modal ===== */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45);
    z-index: 2000; align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay.show { display: flex; }
.modal {
    background: #fff; border-radius: 14px; width: 100%; max-width: 520px;
    max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-header {
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.modal-header h3 { font-size: 1.05rem; }
.modal-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; }
.modal-body { padding: 1.25rem; }
.modal-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; gap: .5rem; justify-content: flex-end; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .sidebar { transform: translateX(100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: block; }
    .main-content { margin-right: 0; }
    .menu-toggle { display: block; }
    .overlay.show { display: block; }
    .form-row { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
    .content-wrapper { padding: 1rem; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-card .stat-value { font-size: 1.4rem; }
    th, td { padding: .55rem .6rem; font-size: .85rem; }
}
