/* ============================================================
   FARM MANAGEMENT SYSTEM — Main Stylesheet
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Surfaces */
  --bg-page:       #F2F1EE;
  --bg-card:       #FFFFFF;
  --bg-card-alt:   #F9F8F6;
  --sidebar-bg:    #18202E;
  --sidebar-hover: #242D3F;
  --sidebar-act:   #2D3A52;

  /* Text */
  --text-primary:  #1A1A18;
  --text-secondary:#52514E;
  --text-muted:    #898780;
  --text-white:    #FFFFFF;
  --sidebar-text:  #9DA8B7;
  --sidebar-act-text: #FFFFFF;

  /* Borders */
  --border:        rgba(0,0,0,0.08);
  --border-strong: rgba(0,0,0,0.14);

  /* Brand colors */
  --accent:        #2A78D6;
  --accent-bg:     #E6F1FB;
  --accent-text:   #185FA5;
  --success:       #1BAF7A;
  --success-bg:    #E1F5EE;
  --success-text:  #0F6E56;
  --warning:       #BA7517;
  --warning-bg:    #FAEEDA;
  --warning-text:  #854F0B;
  --danger:        #E24B4A;
  --danger-bg:     #FCEBEB;
  --danger-text:   #A32D2D;
  --purple:        #534AB7;
  --purple-bg:     #EEEDFE;
  --purple-text:   #3C3489;

  /* Module colors */
  --m-livestock:  #1BAF7A;
  --m-realestate: #2A78D6;
  --m-farm:       #BA7517;

  /* Layout */
  --sidebar-w:    230px;
  --header-h:     56px;
  --radius-sm:    6px;
  --radius:       10px;
  --radius-lg:    14px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.06);
  --shadow:       0 2px 8px rgba(0,0,0,.08);
  --transition:   .15s ease;
}

/* ─── Base ───────────────────────────────────────────────── */
html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: 'Segoe UI', 'Noto Sans Arabic', Tahoma, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ─── Layout ─────────────────────────────────────────────── */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ─── Sidebar ────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow: hidden;
  transition: transform var(--transition);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  text-decoration: none;
}
.sidebar-logo-icon {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: rgba(255,255,255,.12);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: #fff;
  flex-shrink: 0;
}
.sidebar-logo-text { font-size: 13px; font-weight: 600; color: #fff; line-height: 1.3; }
.sidebar-logo-sub  { font-size: 10px; color: var(--sidebar-text); }

.sidebar-section {
  font-size: 10px;
  font-weight: 600;
  color: rgba(255,255,255,.3);
  letter-spacing: .6px;
  padding: 14px 16px 4px;
  text-transform: uppercase;
}

.sidebar-nav { padding: 6px 0; flex: 1; overflow-y: auto; min-height: 0; }
.sidebar-nav { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.2) transparent; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 16px;
  color: var(--sidebar-text);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
  border: none; background: none; width: 100%; text-align: inherit;
}
.nav-item i { font-size: 16px; flex-shrink: 0; width: 18px; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active {
  background: var(--sidebar-act);
  color: var(--sidebar-act-text);
  font-weight: 500;
}
.nav-badge {
  margin-inline-start: auto;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(255,255,255,.1);
  color: var(--sidebar-text);
}
.nav-badge.alert { background: var(--danger-bg); color: var(--danger); }

.sidebar-module-badge {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-inline-start: auto;
}
.sidebar-footer {
  position: static;
  flex-shrink: 0;
  margin-top: auto;
  padding: 12px 16px;
  background: rgba(0,0,0,.12);
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-user {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 0;
}
.sidebar-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: #fff;
  flex-shrink: 0;
}
.sidebar-user-name { font-size: 12px; color: #fff; font-weight: 500; }
.sidebar-user-role { font-size: 10px; color: var(--sidebar-text); }

/* ─── Main Content ───────────────────────────────────────── */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--header-h);
  background: var(--bg-card);
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 22px;
  gap: 12px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 15px; font-weight: 600; color: var(--text-primary); flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.page-content { padding: 22px; flex: 1; }

/* ─── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 16px; flex-wrap: wrap;
}
.card-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }

/* ─── Stat Cards ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.stat-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  margin-bottom: 10px;
}
.stat-value { font-size: 26px; font-weight: 700; color: var(--text-primary); line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat-trend { font-size: 11px; margin-top: 6px; }

/* ─── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 500;
  padding: 3px 9px; border-radius: 20px;
  white-space: nowrap;
}
.badge-success  { background: var(--success-bg);  color: var(--success-text); }
.badge-warning  { background: var(--warning-bg);  color: var(--warning-text); }
.badge-danger   { background: var(--danger-bg);   color: var(--danger-text);  }
.badge-accent   { background: var(--accent-bg);   color: var(--accent-text);  }
.badge-purple   { background: var(--purple-bg);   color: var(--purple-text);  }
.badge-neutral  { background: var(--bg-card-alt); color: var(--text-muted); border: 0.5px solid var(--border); }

/* ─── Table ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead { background: var(--bg-card-alt); }
th {
  padding: 10px 14px;
  font-weight: 600; font-size: 12px;
  color: var(--text-secondary);
  text-align: inherit;
  border-bottom: 0.5px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 11px 14px;
  color: var(--text-primary);
  border-bottom: 0.5px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-card-alt); }
.td-muted { color: var(--text-muted); font-size: 12px; }

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  cursor: pointer; border: 0.5px solid transparent;
  font-family: inherit;
  transition: all var(--transition);
  white-space: nowrap; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn i { font-size: 15px; }

.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #1d6abf; border-color: #1d6abf; }

.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #169966; border-color: #169966; }

.btn-outline {
  background: transparent; color: var(--text-secondary);
  border-color: var(--border-strong);
}
.btn-outline:hover { background: var(--bg-card-alt); color: var(--text-primary); }

.btn-danger  { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #c73b3b; }

.btn-danger-outline {
  background: transparent; color: var(--danger-text); border-color: var(--danger);
}
.btn-danger-outline:hover { background: var(--danger-bg); }

.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-sm i { font-size: 13px; }

/* ─── Forms ──────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 12px; font-weight: 500; color: var(--text-secondary); }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="tel"],
select,
textarea {
  width: 100%;
  padding: 8px 12px;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit; font-size: 13px;
  background: var(--bg-card);
  color: var(--text-primary);
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(42,120,214,.1);
}
input.error, select.error, textarea.error { border-color: var(--danger); }
textarea { resize: vertical; min-height: 80px; }
.field-error { font-size: 11px; color: var(--danger); margin-top: 2px; }

.form-actions {
  display: flex; gap: 8px; margin-top: 18px;
  padding-top: 16px; border-top: 0.5px solid var(--border);
}

/* ─── Alerts / Flash ─────────────────────────────────────── */
.alert {
  padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 13px; margin-bottom: 16px;
  display: flex; align-items: flex-start; gap: 8px;
}
.alert-success { background: var(--success-bg); color: var(--success-text); border: 0.5px solid #9FE1CB; }
.alert-danger  { background: var(--danger-bg);  color: var(--danger-text);  border: 0.5px solid #F7C1C1; }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); border: 0.5px solid #FAC775; }

/* ─── Empty State ────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 40px 20px;
}
.empty-state i {
  font-size: 48px; color: var(--text-muted);
  display: block; margin-bottom: 12px;
}
.empty-state h3 { font-size: 15px; color: var(--text-secondary); font-weight: 500; }
.empty-state p  { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ─── Modal ──────────────────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  align-items: center; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  width: 90%; max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px 24px;
  position: relative;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 20px; color: var(--text-muted); line-height: 1;
}
.modal-close:hover { color: var(--text-primary); }

/* ─── Confirm Dialog ─────────────────────────────────────── */
.confirm-box {
  background: var(--danger-bg);
  border: 0.5px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-top: 10px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap;
}
.confirm-box p { font-size: 13px; color: var(--danger-text); flex: 1; }

/* ─── Breadcrumb ─────────────────────────────────────────── */
.breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted);
  margin-bottom: 16px;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb-sep { color: var(--border-strong); font-size: 10px; }

/* ─── Utilities ──────────────────────────────────────────── */
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.text-muted  { color: var(--text-muted); }
.text-small  { font-size: 12px; }
.text-right  { text-align: end; }
.fw-500 { font-weight: 500; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 14px; }
.mb-3 { margin-bottom: 14px; }
.mb-4 { margin-bottom: 20px; }
.me-1 { margin-inline-end: 4px; }

/* ─── Login Page ─────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--sidebar-bg);
}
.login-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  width: 100%; max-width: 400px;
}
.login-logo {
  text-align: center; margin-bottom: 28px;
}
.login-logo-icon {
  width: 52px; height: 52px;
  background: var(--success-bg);
  border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 26px; color: var(--success); margin-bottom: 10px;
}
.login-title { font-size: 18px; font-weight: 700; color: var(--text-primary); }
.login-sub   { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ─── Module Dashboard Cards ─────────────────────────────── */
.module-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.module-card {
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex; flex-direction: column; gap: 10px;
  text-decoration: none; color: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.module-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
  text-decoration: none;
}
.module-card-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}
.module-card-name { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.module-card-desc { font-size: 12px; color: var(--text-muted); line-height: 1.5; }

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .page-content { padding: 14px; }
}


/* ══════════════════════════════════════════════════════════
   DARK MODE
   ══════════════════════════════════════════════════════════ */

[data-theme="dark"] {
  --bg-page:      #0F1117;
  --bg-card:      #181C25;
  --bg-card-alt:  #1E2330;
  --sidebar-bg:   #0C0E16;
  --sidebar-hover:#161B29;
  --sidebar-act:  #1D2540;
  --text-primary: #E9E8E5;
  --text-secondary:#A8A7A4;
  --text-muted:   #6A6967;
  --border:       rgba(255,255,255,0.07);
  --border-strong:rgba(255,255,255,0.13);
  --sidebar-text: #8796AE;
  --accent-bg:    rgba(42,120,214,0.18);
  --accent-text:  #6BB4FF;
  --success-bg:   rgba(27,175,122,0.14);
  --success-text: #4AD8A4;
  --warning-bg:   rgba(186,117,23,0.16);
  --warning-text: #F5B944;
  --danger-bg:    rgba(226,75,74,0.16);
  --danger-text:  #FF8282;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.3);
  --shadow:       0 2px 8px rgba(0,0,0,.4);
}

[data-theme="dark"] .sidebar { border-inline-end-color: rgba(255,255,255,0.05); }
[data-theme="dark"] .topbar  { border-bottom-color: rgba(255,255,255,0.06); }
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea { background: var(--bg-card-alt); color: var(--text-primary); border-color: rgba(255,255,255,0.12); }
[data-theme="dark"] table thead { background: var(--bg-card-alt); }
[data-theme="dark"] tbody tr:hover { background: var(--bg-card-alt); }
[data-theme="dark"] .stat-card { background: var(--bg-card); }
[data-theme="dark"] .card { background: var(--bg-card); }
[data-theme="dark"] .modal { background: var(--bg-card); }

/* ══════════════════════════════════════════════════════════
   DASHBOARD WIDGETS
   ══════════════════════════════════════════════════════════ */

.widget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.widget { background: var(--bg-card); border: 0.5px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.widget-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 0.5px solid var(--border);
  background: var(--bg-card-alt);
}
.widget-title { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.widget-body { padding: 14px 16px; }
.widget-hidden { display: none !important; }
.widget-toggle-btn {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  font-size: 16px; padding: 2px 6px; border-radius: var(--radius-sm);
  transition: all .1s;
}
.widget-toggle-btn:hover { background: var(--border); color: var(--text-primary); }

/* Dashboard customizer panel */
.dash-customizer {
  position: fixed;
  top: 0; inset-inline-end: 0;
  width: 280px; height: 100vh;
  background: var(--bg-card);
  border-inline-start: 0.5px solid var(--border);
  padding: 20px;
  transform: translateX(100%);
  transition: transform .25s ease;
  z-index: 300;
  overflow-y: auto;
}
[dir="rtl"] .dash-customizer { transform: translateX(-100%); }
.dash-customizer.open { transform: translateX(0) !important; }

/* Permission cards */
.perm-card { border: 0.5px solid var(--border); border-radius: var(--radius); padding: 12px; }
.perm-icon { font-size: 22px; }

/* Notification dot animation */
@keyframes pulse-dot {
  0%,100% { opacity: 1; }
  50% { opacity: .5; }
}
.notif-pulse { animation: pulse-dot 2s infinite; }

/* Admin panel sidebar link highlight */
.nav-item.admin-link { border-inline-start: 2px solid transparent; }
.nav-item.admin-link.active { border-inline-start-color: var(--danger); }

/* Responsive sidebar overlay */
@media (max-width: 768px) {
  #sidebar-toggle { display: flex !important; }
}


/* ══ Sidebar Accordion Navigation ══════════════════════════ */
.nav-group { margin-bottom: 2px; }

.nav-group-toggle {
    display: flex; align-items: center; gap: 9px;
    padding: 8px 16px; border-radius: var(--radius);
    cursor: pointer; width: 100%;
    background: none; border: none; text-align: inherit;
    color: var(--sidebar-text); font-family: inherit;
    font-size: 13px; font-weight: 500;
    transition: background .12s, color .12s;
    position: relative;
}
.nav-group-toggle:hover { background: var(--sidebar-hover); color: #fff; }
.nav-group-toggle.open  { color: #fff; }
.nav-group-toggle .chevron {
    margin-inline-start: auto;
    font-size: 12px;
    transition: transform .2s;
    opacity: 0.5;
}
.nav-group-toggle.open .chevron { transform: rotate(90deg); opacity: 1; }
.nav-group-icon {
    width: 22px; height: 22px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; flex-shrink: 0;
}

/* Sub-groups (sections inside a module) */
.nav-sub-group { overflow: hidden; max-height: 0; transition: max-height .25s ease; }
.nav-sub-group.open { max-height: 600px; }

.nav-sub-label {
    display: flex; align-items: center; gap: 7px;
    padding: 6px 16px 4px 16px;
    font-size: 10px; font-weight: 600; letter-spacing: .07em;
    color: var(--sidebar-text); opacity: .65; text-transform: uppercase;
    margin-top: 4px;
}
[dir="rtl"] .nav-sub-label { padding: 6px 28px 4px 16px; }
[dir="ltr"] .nav-sub-label { padding: 6px 16px 4px 28px; }

.nav-sub-item {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 16px;
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--sidebar-text);
    font-size: 13px;
    transition: background .1s, color .1s;
    margin: 1px 6px;
}
[dir="rtl"] .nav-sub-item { padding: 6px 32px 6px 16px; }
[dir="ltr"] .nav-sub-item { padding: 6px 16px 6px 32px; }
.nav-sub-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-sub-item.active {
    background: var(--sidebar-act);
    color: var(--sidebar-act-text);
    font-weight: 500;
}
.nav-sub-item .ti { font-size: 14px; flex-shrink: 0; }

/* Serial number autocomplete */
.serial-dd {
    background: var(--bg-card);
    border: 0.5px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,.12);
    max-height: 220px; overflow-y: auto;
    position: absolute; width: 100%; top: 100%;
    z-index: 200; margin-top: 3px;
}
.dd-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 12px; cursor: pointer; font-size: 13px;
    border-bottom: 0.5px solid var(--border);
    transition: background .1s;
}
.dd-item:last-child { border-bottom: none; }
.dd-item:hover { background: var(--bg-card-alt); }
.dd-empty { padding: 12px; text-align: center; color: var(--text-muted); font-size: 12px; }
.serial-badge { margin-top: 5px; font-size: 12px; }
.serial-ok  { color: var(--success); font-weight: 500; }
.serial-err { color: var(--danger);  font-weight: 500; }
.form-group { position: relative; }


/* ══════════════════════════════════════════════════════════
   SMART DASHBOARD — v2
   ══════════════════════════════════════════════════════════ */

/* 12-column responsive widget grid */
.widget-grid-v2 {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
}
.widget-grid-v2 .widget[data-size="sm"] { grid-column: span 4; }
.widget-grid-v2 .widget[data-size="md"] { grid-column: span 6; }
.widget-grid-v2 .widget[data-size="lg"] { grid-column: span 12; }

@media (max-width: 1200px) {
  .widget-grid-v2 .widget[data-size="sm"] { grid-column: span 6; }
}
@media (max-width: 767px) {
  .widget-grid-v2 .widget[data-size="sm"],
  .widget-grid-v2 .widget[data-size="md"],
  .widget-grid-v2 .widget[data-size="lg"] { grid-column: span 12; }
}

/* Drag handle + dragging state */
.widget { position: relative; transition: box-shadow .15s, transform .15s, opacity .15s; }
.widget.dragging { opacity: .4; }
.widget.drag-over { box-shadow: 0 0 0 2px var(--accent) inset; }

.widget-drag-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 15px;
  padding: 2px 4px;
  border-radius: 4px;
  flex-shrink: 0;
}
.widget-drag-handle:hover { background: var(--border); color: var(--text-primary); }
.widget-drag-handle:active { cursor: grabbing; }

.widget-header-actions { display: flex; align-items: center; gap: 4px; }
.widget-size-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 11px; font-weight: 600;
  padding: 3px 7px; border-radius: 5px; transition: all .1s;
  font-family: monospace;
}
.widget-size-btn:hover { background: var(--border); color: var(--text-primary); }

/* Period selector pills */
.period-pills {
  display: inline-flex; background: var(--bg-card-alt);
  border-radius: 20px; padding: 3px; gap: 2px;
}
.period-pill {
  padding: 6px 14px; border-radius: 17px; font-size: 12px; font-weight: 500;
  text-decoration: none; color: var(--text-muted); transition: all .15s;
  white-space: nowrap;
}
.period-pill.active { background: var(--bg-card); color: var(--accent); box-shadow: var(--shadow-sm); font-weight: 600; }
.period-pill:hover:not(.active) { color: var(--text-secondary); }

/* KPI card with trend */
.kpi-card {
  background: var(--bg-card); border: 0.5px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px;
  display: flex; flex-direction: column; gap: 4px;
}
.kpi-card-top { display: flex; align-items: flex-start; justify-content: space-between; }
.kpi-icon {
  width: 36px; height: 36px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center; font-size: 17px; flex-shrink: 0;
}
.kpi-value { font-size: 22px; font-weight: 700; line-height: 1.1; margin-top: 6px; }
.kpi-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.kpi-trend-row { display: flex; align-items: center; gap: 6px; margin-top: 6px; }

/* Sparkline trend widgets */
.trend-widget-body { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.trend-widget-value { font-size: 24px; font-weight: 700; }
.trend-widget-sub { font-size: 11px; color: var(--text-muted); }

/* Comparison widget bars */
.compare-row { margin-bottom: 14px; }
.compare-row:last-child { margin-bottom: 0; }
.compare-bars { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.compare-bar-track { flex: 1; height: 8px; background: var(--bg-card-alt); border-radius: 4px; overflow: hidden; display: flex; }
.compare-bar-fill { height: 100%; border-radius: 4px; transition: width .4s ease; }

/* Top performers list */
.top-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 0.5px solid var(--border);
}
.top-item:last-child { border-bottom: none; }
.top-rank {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; background: var(--bg-card-alt); color: var(--text-muted);
}
.top-rank.gold   { background: #FEF3E2; color: #BA7517; }
.top-rank.silver { background: #F1EFE8; color: #888780; }
.top-rank.bronze { background: #FCEBEB; color: #A32D2D; }

/* Upcoming tasks timeline */
.upcoming-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 0.5px solid var(--border);
}
.upcoming-item:last-child { border-bottom: none; }
.upcoming-date-chip {
  min-width: 42px; text-align: center; padding: 4px 6px;
  border-radius: 8px; flex-shrink: 0;
}
.upcoming-date-chip .day { font-size: 14px; font-weight: 700; line-height: 1.1; }
.upcoming-date-chip .mon { font-size: 9px; text-transform: uppercase; opacity: .8; }

/* Empty widget state */
.widget-empty {
  text-align: center; padding: 24px 16px; color: var(--text-muted); font-size: 12px;
}
.widget-empty i { font-size: 24px; display: block; margin-bottom: 8px; opacity: .5; }

/* Customizer panel v2 - widget rows with size + drag */
.customizer-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 0.5px solid var(--border);
}
.customizer-row .cz-drag { cursor: grab; color: var(--text-muted); font-size: 14px; }
.customizer-row.cz-dragging { opacity: .4; }
.customizer-size-toggle {
  display: flex; background: var(--bg-card-alt); border-radius: 6px; padding: 2px; gap: 1px;
}
.customizer-size-toggle button {
  border: none; background: none; padding: 3px 7px; border-radius: 4px;
  font-size: 10px; font-weight: 600; cursor: pointer; color: var(--text-muted);
}
.customizer-size-toggle button.active { background: var(--bg-card); color: var(--accent); }

/* Customizer save indicator */
.cz-save-toast {
  position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(-50%);
  background: var(--text-primary); color: var(--bg-card); padding: 8px 18px;
  border-radius: 20px; font-size: 12px; font-weight: 500; z-index: 999;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
[dir="rtl"] .cz-save-toast { transform: translateX(50%); }
.cz-save-toast.show { opacity: 1; }

/* ══════════════════════════════════════════════════════════
   SIDEBAR — Section-level collapse + scroll fixes
   ══════════════════════════════════════════════════════════ */

/* Defensive: prevent flexbox min-height:auto from breaking
   the sidebar's overflow scroll when content is tall */
.sidebar-nav { min-height: 0; }

/* Visible, themed scrollbar so users can SEE there's more to scroll */
.sidebar { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.25) transparent; }
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 3px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.35); }

/* Section-level toggle (collapsible groups within an open module) */
.nav-section-toggle {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; background: none; border: none; cursor: pointer;
  padding: 9px 16px 4px; margin-top: 4px;
  font-size: 13px; font-weight: 600;
  color: var(--sidebar-text); opacity: .8;
  font-family: inherit; text-align: inherit;
  transition: opacity .12s;
}
.nav-section-toggle:hover { opacity: 1; }
.nav-section-toggle.open { opacity: 1; }
.section-chevron {
  font-size: 11px;
  transition: transform .2s;
  opacity: .7;
}
.nav-section-toggle.open .section-chevron { transform: rotate(90deg); }

.nav-section-items {
  overflow: hidden;
  max-height: 0;
  transition: max-height .25s ease;
}
.nav-section-items.open { max-height: 600px; }

/* ══════════════════════════════════════════════════════════
   TABLET GRID NAVIGATION — 768px to 1023px ONLY
   Hidden on all other viewports via display:none.
   JS openTabletNav() removes display:none, then adds .open
   ══════════════════════════════════════════════════════════ */

/* The overlay — hidden everywhere by default */
.tablet-nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  opacity: 0;
  transition: opacity .25s;
}
.tablet-nav-overlay.open { opacity: 1; }

/* The panel — hidden on desktop and mobile; shown only on tablet */
.tablet-nav-panel {
  display: none;
  position: fixed;
  top: 0;
  bottom: 0;
  width: min(360px, 88vw);
  background: var(--bg-card);
  z-index: 201;
  flex-direction: column;
  box-shadow: 0 0 40px rgba(0,0,0,.25);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
}
/* Toggle button — hidden everywhere except tablet via media query below */
.tablet-nav-toggle { display: none; }

/* ── Shared panel content styles (always safe to define globally) ── */
.tablet-nav-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 0.5px solid var(--border); flex-shrink: 0; gap: 10px;
}
.tablet-nav-app-name { font-size: 14px; font-weight: 700; color: var(--text-primary); }
.tablet-nav-close {
  width: 34px; height: 34px; border: 0.5px solid var(--border);
  background: var(--bg-card-alt); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 18px; color: var(--text-muted); flex-shrink: 0;
}
.tablet-nav-close:hover { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.tablet-nav-body { flex: 1; overflow-y: auto; padding: 12px 14px; }
.tablet-module-heading {
  font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-muted); padding: 10px 4px 6px; margin-top: 4px;
}
.tablet-section-heading {
  font-size: 11px; font-weight: 600; color: var(--text-secondary); padding: 8px 4px 4px; margin-top: 6px;
}
.tablet-tile-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 4px; }
.tablet-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 5px; padding: 12px 6px 10px; border-radius: var(--radius);
  border: 0.5px solid var(--border); background: var(--bg-card-alt);
  text-decoration: none; cursor: pointer; min-height: 72px; text-align: center;
  transition: background .12s, border-color .12s, transform .08s;
  -webkit-tap-highlight-color: transparent;
}
.tablet-tile:active { transform: scale(.95); }
.tablet-tile:hover, .tablet-tile.active { background: var(--accent-bg); border-color: var(--accent); }
.tablet-tile i { font-size: 22px; color: var(--text-secondary); transition: color .12s; }
.tablet-tile:hover i, .tablet-tile.active i { color: var(--accent); }
.tablet-tile span {
  font-size: 10.5px; font-weight: 500; line-height: 1.3;
  color: var(--text-secondary); word-break: break-word; transition: color .12s;
}
.tablet-tile:hover span, .tablet-tile.active span { color: var(--accent-text); }
.tablet-single-tile {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px;
  border-radius: var(--radius); background: var(--bg-card-alt);
  border: 0.5px solid var(--border); text-decoration: none; margin-bottom: 6px;
  -webkit-tap-highlight-color: transparent; transition: background .12s, border-color .12s;
}
.tablet-single-tile:hover, .tablet-single-tile.active { background: var(--accent-bg); border-color: var(--accent); }
.tablet-single-tile i { font-size: 18px; color: var(--accent); width: 24px; text-align: center; }
.tablet-single-tile span { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.tablet-nav-footer {
  padding: 12px 16px; border-top: 0.5px solid var(--border);
  display: flex; align-items: center; gap: 10px; background: var(--bg-card-alt); flex-shrink: 0;
}
.tablet-nav-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent);
  color: white; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.tablet-nav-user-name { font-size: 13px; font-weight: 600; }
.tablet-nav-user-role { font-size: 11px; color: var(--text-muted); }

/* ── Tablet-only activation ──────────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
  /* Show the tablet toggle button */
  .tablet-nav-toggle { display: flex !important; }

  /* Hide the old sidebar on tablets */
  .sidebar { display: none !important; }
  .app-wrapper { display: block !important; }
  .main-wrapper { width: 100% !important; }

  /* Panel slide-in: LTR starts from left, RTL starts from right */
  [dir="ltr"] .tablet-nav-panel {
    left: 0;
    transform: translateX(-110%);
  }
  [dir="rtl"] .tablet-nav-panel {
    right: 0;
    transform: translateX(110%);
  }
  .tablet-nav-panel.open {
    transform: translateX(0) !important;
  }
  /* The overlay becomes block so it can fade in/out */
  .tablet-nav-overlay {
    display: block;
  }
}
