/* ============================================================
   وات‌متر هوشمند – طراحی کلاسیک داشبورد
   سایدبار از بالا، هدر در کنار سایدبار
   ============================================================ */

/* ===== متغیرها ===== */
:root {
    --primary: #1A80F8;
    --primary-dark: #1A5CB5;
    --primary-glow: rgba(26, 128, 248, 0.2);
    --primary-light: rgba(26, 128, 248, 0.06);

    --success: #22C55E;
    --danger: #EF4444;
    --warning: #F59E0B;
    --info: #3B82F6;
    --purple: #8B5CF6;

    --bg-body: #F0F4F9;
    --bg-card: #FFFFFF;
    --bg-card-alt: #F7FAFC;
    --bg-sidebar: #0B1A30;
    --bg-header: #FFFFFF;
    --bg-input: #F0F4F9;

    --text-color: #1A2A3A;
    --text-muted: #6B7D95;
    --text-sidebar: #B0C8E0;
    --text-sidebar-active: #FFFFFF;
    --border-color: #E2E8F0;

    --shadow: 0 2px 12px rgba(19, 30, 54, 0.05);
    --shadow-hover: 0 8px 30px rgba(19, 30, 54, 0.10);
    --shadow-header: 0 1px 20px rgba(0, 0, 0, 0.04);
    --shadow-dropdown: 0 12px 40px rgba(0, 0, 0, 0.12);

    --sidebar-width: 240px;
    --header-height: 64px;
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 8px;

    --font: 'Vazirmatn', 'Tahoma', sans-serif;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== حالت تاریک ===== */
body.dark-mode {
    --bg-body: #080E1A;
    --bg-card: #101B2E;
    --bg-card-alt: #0D1628;
    --bg-header: #0B1525;
    --bg-input: #1A2338;

    --text-color: #E2E8F0;
    --text-muted: #8AA0B8;
    --text-sidebar: #8AA0B8;
    --text-sidebar-active: #FFFFFF;
    --border-color: #1A2D4A;

    --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    --shadow-hover: 0 8px 30px rgba(0, 0, 0, 0.5);
    --shadow-header: 0 1px 20px rgba(0, 0, 0, 0.3);
    --shadow-dropdown: 0 12px 40px rgba(0, 0, 0, 0.5);
}

/* ===== Reset ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
html {
    scroll-behavior: smooth;
}
body {
    font-family: var(--font);
    background: var(--bg-body);
    color: var(--text-color);
    direction: rtl;
    min-height: 100vh;
    transition: background var(--transition), color var(--transition);
    display: flex;
    overflow-x: hidden;
}
a {
    text-decoration: none;
    color: inherit;
}
ul {
    list-style: none;
}
::selection {
    background: var(--primary);
    color: #fff;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 10px;
}

/* ===== Sidebar (از بالا شروع می‌شود) ===== */
.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    padding: 20px 12px 20px;
    overflow-y: auto;
    z-index: 1000;
    transition: transform var(--transition);
    border-left: 1px solid rgba(255, 255, 255, 0.04);
}
.sidebar .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    margin-bottom: 16px;
}
.sidebar .sidebar-brand .brand-icon {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
    flex-shrink: 0;
}
.sidebar .sidebar-brand .brand-text span {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    display: block;
    line-height: 1.2;
}
.sidebar .sidebar-brand .brand-text small {
    font-size: 10px;
    opacity: 0.5;
    display: block;
    line-height: 1.2;
}
.sidebar .sidebar-nav ul .nav-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    opacity: 0.3;
    padding: 16px 8px 6px;
    font-weight: 600;
    color: var(--text-sidebar);
}
.sidebar .sidebar-nav ul .nav-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-sidebar);
    transition: all 0.2s;
    margin-bottom: 2px;
    position: relative;
}
.sidebar .sidebar-nav ul .nav-item a:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}
.sidebar .sidebar-nav ul .nav-item a.active {
    background: var(--primary-glow);
    color: var(--text-sidebar-active);
}
.sidebar .sidebar-nav ul .nav-item a.active::before {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 18px;
    background: var(--primary);
    border-radius: 0 4px 4px 0;
}
.sidebar .sidebar-nav ul .nav-item a i {
    width: 20px;
    text-align: center;
    font-size: 15px;
    flex-shrink: 0;
}
.sidebar .sidebar-nav ul .nav-item a .badge {
    margin-right: auto;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    padding: 0 8px;
    border-radius: 20px;
    font-weight: 600;
}
.sidebar .sidebar-nav ul .nav-item.logout {
    margin-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    padding-top: 12px;
}
.sidebar .sidebar-nav ul .nav-item.logout a {
    color: var(--danger);
}
.sidebar .sidebar-nav ul .nav-item.logout a:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* ===== Main Content (در کنار سایدبار) ===== */
.main-content {
    flex: 1;
    margin-right: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin var(--transition);
}

/* ===== Header (در کنار سایدبار) ===== */
.header {
    position: sticky;
    top: 0;
    z-index: 999;
    height: var(--header-height);
    background: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background var(--transition), border var(--transition);
    box-shadow: var(--shadow-header);
}
.header .header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}
.header .header-left .toggle-sidebar {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-xs);
    transition: all 0.2s;
}
.header .header-left .toggle-sidebar:hover {
    background: var(--bg-card-alt);
    color: var(--primary);
}
.header .header-left .brand {
    display: flex;
    align-items: center;
    gap: 10px;
}
.header .header-left .brand .brand-icon {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 14px;
    flex-shrink: 0;
}
.header .header-left .brand .brand-text span {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-color);
    display: block;
    line-height: 1.1;
}
.header .header-left .brand .brand-text small {
    display: none;
}
.header .header-left .search-box {
    display: flex;
    align-items: center;
    background: var(--bg-input);
    border-radius: 30px;
    padding: 4px 14px;
    border: 1px solid transparent;
    transition: all 0.2s;
    gap: 8px;
    margin-right: 8px;
}
.header .header-left .search-box:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
    background: var(--bg-card);
}
.header .header-left .search-box input {
    border: none;
    background: transparent;
    padding: 6px 4px;
    font-size: 13px;
    color: var(--text-color);
    outline: none;
    width: 160px;
}
.header .header-left .search-box i {
    color: var(--text-muted);
    font-size: 15px;
}

.header .header-right {
    display: flex;
    align-items: center;
    gap: 6px;
}
.header .header-right button {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 17px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.header .header-right button:hover {
    background: var(--bg-card-alt);
    color: var(--primary);
}
.header .header-right .theme-toggle .fa-moon {
    display: inline;
}
.header .header-right .theme-toggle .fa-sun {
    display: none;
}
body.dark-mode .header .header-right .theme-toggle .fa-moon {
    display: none;
}
body.dark-mode .header .header-right .theme-toggle .fa-sun {
    display: inline;
}
.header .header-right .notif-btn {
    position: relative;
}
.header .header-right .notif-btn .badge {
    position: absolute;
    top: 0;
    right: 0;
    background: var(--danger);
    color: #fff;
    font-size: 9px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}
.header .header-right .user-dropdown {
    position: relative;
}
.header .header-right .user-dropdown .user-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 12px 4px 8px;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}
.header .header-right .user-dropdown .user-trigger:hover {
    background: var(--bg-card-alt);
    border-color: var(--border-color);
}
.header .header-right .user-dropdown .user-trigger .avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
}
.header .header-right .user-dropdown .user-trigger .user-info {
    line-height: 1.2;
}
.header .header-right .user-dropdown .user-trigger .user-info .name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-color);
}
.header .header-right .user-dropdown .user-trigger .user-info .role {
    font-size: 10px;
    color: var(--text-muted);
}
.header .header-right .user-dropdown .user-trigger i {
    color: var(--text-muted);
    font-size: 12px;
    margin-right: 4px;
}
.header .header-right .user-dropdown .dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 180px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-dropdown);
    padding: 6px 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.96);
    transition: all 0.2s ease;
}
.header .header-right .user-dropdown .dropdown-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}
.header .header-right .user-dropdown .dropdown-menu a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    font-size: 13px;
    color: var(--text-color);
    transition: background 0.15s;
}
.header .header-right .user-dropdown .dropdown-menu a:hover {
    background: var(--bg-card-alt);
}
.header .header-right .user-dropdown .dropdown-menu a i {
    width: 18px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}
.header .header-right .user-dropdown .dropdown-menu .divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}
.header .header-right .user-dropdown .dropdown-menu a.logout {
    color: var(--danger);
}
.header .header-right .user-dropdown .dropdown-menu a.logout i {
    color: var(--danger);
}

/* ===== Page Content ===== */
.page-content {
    padding: 24px 28px;
    flex: 1;
}
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
}
.page-header h1 {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.3px;
}
.page-header p {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}
.page-header .actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ===== Cards ===== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    padding: 20px 24px;
    box-shadow: var(--shadow);
    transition: all 0.25s;
    margin-bottom: 16px;
}
.card:hover {
    box-shadow: var(--shadow-hover);
}
.card-title {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-title i {
    color: var(--primary);
    margin-left: 8px;
}

/* ===== Grids ===== */
.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}
.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

/* ===== Stat Cards ===== */
.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 18px 20px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    transition: all 0.25s;
    position: relative;
    overflow: hidden;
}
.stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
    opacity: 0.6;
    border-radius: 0 4px 4px 0;
}
.stat-card:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-3px);
}
.stat-card .label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}
.stat-card .value {
    font-size: 26px;
    font-weight: 800;
    font-family: var(--font);
    margin: 4px 0;
}
.stat-card .change {
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}
.stat-card .change.up {
    color: var(--success);
}
.stat-card .change.down {
    color: var(--danger);
}

/* ===== Tables ===== */
.table-wrap {
    overflow-x: auto;
    margin: 0 -4px;
    padding: 0 4px;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 600px;
}
table th {
    text-align: right;
    padding: 10px 12px;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
}
table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
}
table tbody tr {
    transition: background 0.15s;
}
table tbody tr:hover {
    background: var(--bg-card-alt);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    border-radius: 30px;
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.25s;
    font-family: var(--font);
}
.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 14px var(--primary-glow);
    transform: translateY(-1px);
}
.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border-color);
    color: var(--text-color);
}
.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}
.btn-success {
    background: var(--success);
    color: #fff;
}
.btn-success:hover {
    box-shadow: 0 4px 14px rgba(34, 197, 94, 0.3);
    transform: translateY(-1px);
}
.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover {
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.3);
    transform: translateY(-1px);
}
.btn-warning {
    background: var(--warning);
    color: #fff;
}
.btn-warning:hover {
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.3);
    transform: translateY(-1px);
}
.btn-sm {
    padding: 4px 14px;
    font-size: 11px;
    border-radius: 20px;
}

/* ===== Badges ===== */
.badge-status {
    padding: 2px 12px;
    border-radius: 30px;
    font-size: 11px;
    font-weight: 600;
    display: inline-block;
}
.badge-status.success {
    background: rgba(34, 197, 94, 0.14);
    color: var(--success);
}
.badge-status.danger {
    background: rgba(239, 68, 68, 0.14);
    color: var(--danger);
}
.badge-status.warning {
    background: rgba(245, 158, 11, 0.14);
    color: var(--warning);
}
.badge-status.info {
    background: rgba(59, 130, 246, 0.14);
    color: var(--info);
}

/* ===== Channel Cards ===== */
.channel-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}
.channel-card {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    transition: all 0.25s;
}
.channel-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
    border-color: var(--primary);
}
.channel-card .name {
    font-weight: 700;
    font-size: 14px;
}
.channel-card .value {
    font-size: 22px;
    font-weight: 800;
    margin: 4px 0;
}
.channel-card .detail {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.channel-card .status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-left: 4px;
}
.channel-card .status-dot.normal {
    background: var(--success);
}
.channel-card .status-dot.warning {
    background: var(--warning);
}
.channel-card .status-dot.danger {
    background: var(--danger);
}
.channel-card .status-text {
    font-size: 12px;
    font-weight: 600;
}
.channel-card .status-text.normal {
    color: var(--success);
}
.channel-card .status-text.warning {
    color: var(--warning);
}
.channel-card .status-text.danger {
    color: var(--danger);
}

/* ===== List Items ===== */
.list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}
.list-item:last-child {
    border-bottom: none;
}
.list-item .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-glow);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}
.list-item .info {
    flex: 1;
}
.list-item .info .name {
    font-weight: 600;
    font-size: 14px;
}
.list-item .info .email {
    font-size: 12px;
    color: var(--text-muted);
}
.list-item .info .role {
    font-size: 11px;
    background: var(--primary-glow);
    color: var(--primary);
    padding: 0 10px;
    border-radius: 10px;
    display: inline-block;
}
.list-item .actions {
    display: flex;
    gap: 6px;
}
.list-item .actions button {
    background: none;
    border: none;
    font-size: 15px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    transition: color 0.2s;
}
.list-item .actions button:hover {
    color: var(--primary);
}
.list-item .actions button.danger:hover {
    color: var(--danger);
}

/* ===== Permissions Table ===== */
.perm-table th,
.perm-table td {
    text-align: center;
}
.perm-table .module {
    text-align: right;
    font-weight: 600;
}
.perm-table .fa-check {
    color: var(--success);
    font-size: 16px;
}
.perm-table .fa-times {
    color: var(--danger);
    font-size: 16px;
}

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}
.modal-overlay.open {
    display: flex;
}
.modal-overlay .modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px 28px;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    animation: scaleIn 0.25s ease;
    border: 1px solid var(--border-color);
}
@keyframes scaleIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}
.modal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.modal .modal-header h3 {
    font-size: 18px;
    font-weight: 700;
}
.modal .modal-header .close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s;
}
.modal .modal-header .close:hover {
    color: var(--danger);
}
.modal .form-group {
    margin-bottom: 14px;
}
.modal .form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
}
.modal .form-group input,
.modal .form-group select {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    color: var(--text-color);
    font-size: 14px;
    font-family: var(--font);
    transition: border 0.2s;
}
.modal .form-group input:focus,
.modal .form-group select:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.modal .btn {
    width: 100%;
    padding: 12px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 15px;
    font-weight: 700;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.2s;
    color: #fff;
    background: var(--primary);
}
.modal .btn:hover {
    background: var(--primary-dark);
    transform: scale(1.01);
}
.modal .btn-secondary {
    background: var(--bg-input);
    color: var(--text-color);
    margin-top: 8px;
}
.modal .btn-secondary:hover {
    background: var(--border-color);
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.toast.show {
    opacity: 1;
    transform: translateY(0);
}
.toast.success {
    background: var(--success);
    color: #fff;
}
.toast.error {
    background: var(--danger);
    color: #fff;
}
.toast.warning {
    background: var(--warning);
    color: #fff;
}
.toast.info {
    background: var(--primary);
    color: #fff;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}
.empty-state i {
    font-size: 40px;
    color: var(--border-color);
    margin-bottom: 12px;
    display: block;
}
.empty-state h4 {
    font-size: 16px;
    color: var(--text-color);
}
.empty-state p {
    font-size: 13px;
}

/* ===== Chart Wrapper ===== */
.chart-wrapper {
    position: relative;
    width: 100%;
    height: 220px;
}
.chart-wrapper canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ===== Switch ===== */
.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.switch .slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #ccc;
    transition: 0.3s;
    border-radius: 26px;
}
.switch .slider::before {
    content: '';
    position: absolute;
    height: 20px;
    width: 20px;
    right: 3px;
    bottom: 3px;
    background: #fff;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
.switch input:checked+.slider {
    background: var(--primary);
}
.switch input:checked+.slider::before {
    transform: translateX(-22px);
}

/* ===== Sidebar Overlay (موبایل) ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    backdrop-filter: blur(4px);
}
.sidebar-overlay.active {
    display: block;
}

/* ===== Form Grid & Modal extras ===== */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
@media (max-width: 600px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
}
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-color);
}
.form-group input,
.form-group select,
.form-group textarea {
    padding: 10px 14px;
    border-radius: var(--radius-xs);
    border: 1px solid var(--border-color);
    background: var(--bg-card-alt);
    color: var(--text-color);
    font-family: var(--font);
    font-size: 13px;
    transition: border 0.2s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 16px;
    margin-top: 8px;
    border-top: 1px solid var(--border-color);
}
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}
.modal-close:hover {
    color: var(--danger);
}
.modal-body {
    padding: 8px 0;
}
.badge-group {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    background: var(--primary-light);
    color: var(--primary);
}
body.dark-mode .badge-group {
    background: rgba(26, 128, 248, 0.15);
}

/* IO Toggle switches */
.io-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}
.io-card {
    background: var(--bg-card-alt);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 16px;
}
.io-card .io-title {
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.io-card .io-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}
.io-card .io-row:last-child {
    border-bottom: none;
}
.switch {
    position: relative;
    width: 48px;
    height: 26px;
}
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.switch .slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #cbd5e1;
    border-radius: 26px;
    transition: 0.3s;
}
.switch .slider:before {
    content: '';
    position: absolute;
    height: 20px;
    width: 20px;
    right: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: 0.3s;
}
.switch input:checked + .slider {
    background: var(--success);
}
.switch input:checked + .slider:before {
    transform: translateX(-22px);
}
.di-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
}
.di-status .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
}
.di-status.on .dot {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}
.di-status.off .dot {
    background: var(--danger);
}

/* Device detail live values */
.live-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}
.live-metric {
    background: var(--bg-card-alt);
    border-radius: var(--radius-sm);
    padding: 14px;
    text-align: center;
    border: 1px solid var(--border-color);
}
.live-metric .lm-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.live-metric .lm-value {
    font-size: 22px;
    font-weight: 800;
}
.live-metric .lm-unit {
    font-size: 12px;
    color: var(--text-muted);
}

/* Settings tabs */
.settings-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0;
}
.settings-tabs .tab {
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}
.settings-tabs .tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.settings-tabs .tab:hover {
    color: var(--primary);
}

/* Signal bar */
.signal-bars {
    display: inline-flex;
    align-items: flex-end;
    gap: 2px;
    height: 14px;
}
.signal-bars span {
    width: 3px;
    background: var(--border-color);
    border-radius: 1px;
}
.signal-bars span.on {
    background: var(--success);
}

/* ============================================================

/* ============================================================
   Responsive – Mobile First Professional
   ============================================================ */

html, body {
    max-width: 100vw;
    overflow-x: hidden;
}

/* Filter bar utility */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}
.filter-bar input,
.filter-bar select {
    padding: 10px 14px;
    border-radius: 30px;
    border: 1px solid var(--border-color);
    background: var(--bg-card-alt);
    color: var(--text-color);
    font-family: var(--font);
    font-size: 13px;
    min-height: 42px;
}
.filter-bar input {
    flex: 1;
    min-width: 160px;
}
.filter-bar select {
    min-width: 130px;
}

/* Desktop table / Mobile cards */
.desktop-only { display: block; }
.mobile-only { display: none; }

/* Table scroll */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
    padding: 0 4px;
}
.table-wrap table {
    width: 100%;
    border-collapse: collapse;
}

/* Device mobile cards */
.device-mobile-card {
    background: var(--bg-card-alt);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-bottom: 10px;
}
.device-mobile-card .dmc-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
}
.device-mobile-card .dmc-name {
    font-weight: 700;
    font-size: 14px;
}
.device-mobile-card .dmc-serial {
    font-size: 11px;
    color: var(--text-muted);
    direction: ltr;
    text-align: right;
}
.device-mobile-card .dmc-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.device-mobile-card .dmc-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    text-align: center;
    margin-bottom: 10px;
    padding: 8px 0;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}
.device-mobile-card .dmc-stats .ds-val {
    font-weight: 700;
    font-size: 13px;
    color: var(--text-color);
}
.device-mobile-card .dmc-stats .ds-lbl {
    font-size: 10px;
    color: var(--text-muted);
}
.device-mobile-card .dmc-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.device-mobile-card .dmc-actions .btn {
    flex: 1;
    min-width: 0;
    justify-content: center;
}

/* Touch-friendly buttons */
.btn {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.btn-sm {
    min-height: 34px;
    padding: 6px 12px;
}

/* ---------- 1200px ---------- */
@media (max-width: 1200px) {
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
    .channel-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ---------- 1024px ---------- */
@media (max-width: 1024px) {
    .grid-3 {
        grid-template-columns: 1fr 1fr;
    }
    .grid-2 {
        grid-template-columns: 1fr;
    }
    .live-metrics {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ---------- 768px (Tablet / Mobile landscape) ---------- */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(100%);
        width: min(300px, 86vw);
        top: 0;
        height: 100%;
        height: 100dvh;
        box-shadow: -10px 0 40px rgba(0, 0, 0, 0.3);
    }
    .sidebar.open {
        transform: translateX(0) !important;
    }
    .main-content {
        margin-right: 0 !important;
        width: 100%;
    }
    .header {
        height: 56px;
        padding: 0 12px;
    }
    .header .header-left .toggle-sidebar {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 42px;
        height: 42px;
        font-size: 20px;
    }
    .header .header-left .brand .brand-text small {
        display: none;
    }
    .header .header-left .search-box input {
        width: 110px;
    }
    .header .header-right .user-dropdown .user-trigger .user-info,
    .header .header-right .user-dropdown .user-trigger > i {
        display: none;
    }
    .header .header-right .theme-toggle,
    .header .header-right .notif-btn {
        width: 40px;
        height: 40px;
    }

    .page-content {
        padding: 14px 12px;
    }
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 16px;
    }
    .page-header h1 {
        font-size: 20px;
    }
    .page-header .actions {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    .page-header .actions .btn {
        flex: 1 1 auto;
        min-width: 120px;
    }

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    .channel-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    .live-metrics {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px;
    }
    .io-grid {
        grid-template-columns: 1fr !important;
    }
    .form-grid {
        grid-template-columns: 1fr !important;
    }

    .stat-card {
        padding: 14px;
    }
    .stat-card .value {
        font-size: 24px;
    }
    .card {
        padding: 14px;
        border-radius: 14px;
        margin-bottom: 12px;
    }
    .card-title {
        font-size: 14px;
        margin-bottom: 12px;
        gap: 8px;
        flex-wrap: wrap;
    }

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .filter-bar input,
    .filter-bar select,
    .filter-bar .btn {
        width: 100%;
        min-width: 0;
    }

    .chart-wrapper {
        height: 210px;
    }

    .modal-overlay .modal {
        max-width: calc(100vw - 20px) !important;
        margin: 10px;
        padding: 18px 16px;
        max-height: calc(100dvh - 24px);
    }
    .modal-footer {
        flex-direction: column-reverse;
        gap: 8px;
    }
    .modal-footer .btn {
        width: 100%;
    }

    .sidebar .sidebar-nav ul .nav-item a {
        padding: 12px 14px;
        font-size: 14px;
        min-height: 46px;
    }

    /* Switch table ↔ cards */
    .desktop-only { display: none !important; }
    .mobile-only { display: block !important; }

    .settings-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 2px;
    }
    .settings-tabs .tab {
        white-space: nowrap;
        flex-shrink: 0;
    }
}

/* ---------- 480px (Phone) ---------- */
@media (max-width: 480px) {
    .header .header-left .search-box {
        display: none;
    }
    .header .header-left .brand .brand-text {
        display: none;
    }
    .page-content {
        padding: 12px 10px;
    }
    .page-header h1 {
        font-size: 18px;
    }
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    /* Keep 2-col for dense stats on phone if preferred - use 2 for stat density */
    .grid-4 {
        grid-template-columns: 1fr 1fr;
    }
    .channel-grid {
        grid-template-columns: 1fr;
    }
    .live-metrics {
        grid-template-columns: 1fr 1fr !important;
    }
    .live-metric .lm-value {
        font-size: 18px;
    }
    .stat-card .value {
        font-size: 22px;
    }
    .device-mobile-card .dmc-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    .chart-wrapper {
        height: 190px;
    }
    table {
        font-size: 12px;
    }
    table th, table td {
        padding: 8px 10px;
    }
}

/* Landscape phone */
@media (max-height: 480px) and (orientation: landscape) {
    .chart-wrapper {
        height: 160px;
    }
    .page-content {
        padding: 10px 14px;
    }
}

/* Safe area (notch) */
@supports (padding: max(0px)) {
    .header {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }
    .page-content {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
    .sidebar {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}
