/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; }
body { font-family: 'Inter', system-ui, -apple-system, sans-serif; background: #f4f6fb; color: #1e293b; min-height: 100vh; }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ── Design Tokens ─────────────────────────────────────────────────────────── */
:root {
  --primary:       #4f46e5;
  --primary-dark:  #3730a3;
  --primary-light: #eef2ff;
  --primary-mid:   #6366f1;
  --success:       #059669;
  --success-bg:    #ecfdf5;
  --warning:       #d97706;
  --warning-bg:    #fffbeb;
  --danger:        #dc2626;
  --danger-bg:     #fef2f2;
  --info:          #0891b2;
  --info-bg:       #f0f9ff;
  --ai-color:      #7c3aed;
  --ai-bg:         #f5f3ff;
  --ai-border:     #ddd6fe;

  --text:          #0f172a;
  --text-muted:    #64748b;
  --text-light:    #94a3b8;
  --border:        #e2e8f0;
  --border-dark:   #cbd5e1;
  --bg:            #f4f6fb;
  --bg-white:      #ffffff;
  --bg-card:       #ffffff;

  --sidebar-bg:    #ffffff;
  --sidebar-w:     256px;
  --header-h:      60px;
  --bottom-nav-h:  64px;

  --shadow-xs:  0 1px 2px rgba(0,0,0,.05);
  --shadow-sm:  0 1px 4px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --shadow:     0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.05);
  --shadow-lg:  0 10px 32px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.06);
  --shadow-glow:0 0 0 3px rgba(79,70,229,.18);

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --transition: .18s cubic-bezier(.4,0,.2,1);
}

/* ── Login ──────────────────────────────────────────────────────────────────── */
#loginScreen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
}
.login-card {
  background: #fff; border-radius: var(--radius-xl); padding: 44px 40px;
  width: min(400px, 92vw); box-shadow: var(--shadow-lg);
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo .logo-icon {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, var(--primary), var(--primary-mid));
  border-radius: var(--radius-lg);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 14px; font-size: 26px; color: #fff;
  box-shadow: 0 4px 14px rgba(79,70,229,.35);
}
.login-logo h1 { font-size: 22px; font-weight: 800; color: var(--text); }
.login-logo p  { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.login-card .form-group { margin-bottom: 16px; }
.login-card label { display: block; font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.login-card input {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); outline: none; transition: border-color var(--transition), box-shadow var(--transition);
  font-size: 14px;
}
.login-card input:focus { border-color: var(--primary); box-shadow: var(--shadow-glow); }
.btn-login {
  width: 100%; padding: 13px; margin-top: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-mid));
  color: #fff; border: none; border-radius: var(--radius-sm);
  font-weight: 700; font-size: 15px; transition: all var(--transition);
  box-shadow: 0 4px 14px rgba(79,70,229,.3);
}
.btn-login:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(79,70,229,.4); }
.login-error { color: var(--danger); font-size: 12px; margin-top: 8px; display: none; }

/* ── App Shell ──────────────────────────────────────────────────────────────── */
#appShell { display: none; height: 100vh; overflow: hidden; }

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  z-index: 200; overflow-y: auto; overflow-x: hidden;
  border-right: 1px solid var(--border);
}
.sidebar-brand {
  padding: 18px 20px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--border); min-height: var(--header-h);
  flex-shrink: 0;
}
.sidebar-brand .brand-icon {
  width: 36px; height: 36px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-mid));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 18px; color: #fff;
  box-shadow: 0 2px 8px rgba(79,70,229,.4);
}
.sidebar-brand .brand-text h2 { font-size: 15px; font-weight: 800; color: var(--text); line-height: 1.2; }
.sidebar-brand .brand-text p  { font-size: 10px; color: var(--text-muted); margin-top: 1px; }

.sidebar-section { padding: 10px 12px 4px; }
.sidebar-section-label {
  font-size: 10px; font-weight: 700; color: #94a3b8;
  letter-spacing: .1em; text-transform: uppercase; padding: 0 10px; margin-bottom: 4px;
}
.sidebar-nav { list-style: none; }
.sidebar-nav li { margin-bottom: 2px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px; padding: 4px 10px;
  border-radius: var(--radius-sm); color: #334155;
  font-size: 13px; font-weight: 500; transition: all var(--transition);
  position: relative;
}
.sidebar-nav a:hover { background: var(--primary-light); color: var(--primary); }
.sidebar-nav a.active {
  background: var(--primary-light);
  color: var(--primary); font-weight: 600;
}
.sidebar-nav a.active::before {
  content: ''; position: absolute; left: 0; top: 20%; bottom: 20%;
  width: 3px; background: var(--primary); border-radius: 0 3px 3px 0;
}
.nav-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; color: inherit; }
.nav-badge {
  margin-left: auto; background: var(--danger); color: #fff;
  border-radius: 10px; font-size: 10px; font-weight: 700;
  padding: 1px 6px; min-width: 18px; text-align: center;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
.header {
  position: fixed; left: var(--sidebar-w); right: 0; top: 0; height: var(--header-h);
  background: var(--bg-white); border-bottom: 1px solid var(--border);
  z-index: 100; display: flex; align-items: center; padding: 0 20px; gap: 12px;
}
.hamburger-btn {
  display: none; width: 36px; height: 36px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); background: transparent;
  flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  flex-shrink: 0;
}
.hamburger-btn span { display: block; width: 16px; height: 2px; background: var(--text-muted); border-radius: 2px; transition: all var(--transition); }
.header-title { font-size: 16px; font-weight: 700; color: var(--text); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Command Search Bar */
.cmd-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 0 12px; height: 36px;
  min-width: 200px; max-width: 280px; cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
  flex-shrink: 0;
}
.cmd-bar:hover { border-color: var(--primary); }
.cmd-bar-icon { font-size: 14px; color: var(--text-light); }
.cmd-bar-text { font-size: 12px; color: var(--text-light); flex: 1; }
.cmd-bar-kbd { font-size: 10px; color: var(--text-light); background: var(--border); padding: 1px 5px; border-radius: 4px; font-family: monospace; }

.header-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.header-tenant {
  background: var(--primary-light); color: var(--primary);
  font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 20px;
}
.header-alert-btn {
  width: 36px; height: 36px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-white); display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--text-muted); position: relative; transition: all var(--transition);
}
.header-alert-btn:hover { border-color: var(--primary); color: var(--primary); }
.alert-badge {
  position: absolute; top: -5px; right: -5px; background: var(--danger); color: #fff;
  border-radius: 50%; width: 17px; height: 17px; font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; border: 2px solid #fff;
}
.user-menu {
  display: flex; align-items: center; gap: 8px; padding: 5px 10px;
  border-radius: var(--radius-sm); cursor: pointer; transition: background var(--transition);
}
.user-menu:hover { background: var(--bg); }
.user-avatar {
  width: 32px; height: 32px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-mid));
  color: #fff; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.user-info .uname { font-size: 12px; font-weight: 600; color: var(--text); }
.user-info .urole { font-size: 10px; color: var(--text-muted); }
.logout-btn {
  padding: 6px 14px; background: transparent; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-muted); font-size: 12px; font-weight: 600;
  transition: all var(--transition);
}
.logout-btn:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-bg); }

/* ── Main Content ───────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w); margin-top: var(--header-h);
  padding: 24px; min-height: calc(100vh - var(--header-h));
  overflow-y: auto; max-height: calc(100vh - var(--header-h));
}

/* ── Page Header ────────────────────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-header h1 { font-size: 20px; font-weight: 800; color: var(--text); flex: 1; min-width: 0; }
.page-header p  { font-size: 12px; color: var(--text-muted); }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card); border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.card-header h3 { font-size: 14px; font-weight: 700; color: var(--text); flex: 1; }
.card-body { padding: 20px; }

/* ── KPI Cards ──────────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px; margin-bottom: 20px;
}
.kpi-card {
  background: var(--bg-card); border-radius: var(--radius);
  padding: 18px 20px; border: 1px solid var(--border);
  box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi-card::after {
  content: ''; position: absolute; top: 0; right: 0;
  width: 60px; height: 60px; border-radius: 0 0 0 60px;
  opacity: .06;
}
.kpi-blue   { border-top: 3px solid var(--primary); }
.kpi-blue::after   { background: var(--primary); }
.kpi-green  { border-top: 3px solid var(--success); }
.kpi-green::after  { background: var(--success); }
.kpi-yellow { border-top: 3px solid var(--warning); }
.kpi-yellow::after { background: var(--warning); }
.kpi-red    { border-top: 3px solid var(--danger); }
.kpi-red::after    { background: var(--danger); }
.kpi-purple { border-top: 3px solid var(--ai-color); }
.kpi-purple::after { background: var(--ai-color); }
.kpi-label { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.kpi-value { font-size: 28px; font-weight: 800; color: var(--text); margin: 6px 0 3px; line-height: 1; }
.kpi-sub   { font-size: 11px; color: var(--text-muted); }
.kpi-icon  { font-size: 26px; position: absolute; top: 16px; right: 18px; opacity: .55; }

/* ── AI Health Score ────────────────────────────────────────────────────────── */
.ai-score-ring {
  display: flex; align-items: center; gap: 24px; padding: 20px;
}
.score-circle {
  width: 90px; height: 90px; border-radius: 50%; flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: conic-gradient(var(--primary) calc(var(--pct, 0) * 1%), var(--border) 0);
  position: relative;
}
.score-circle::before {
  content: ''; position: absolute; inset: 9px;
  background: var(--bg-white); border-radius: 50%;
}
.score-circle-val {
  position: relative; z-index: 1;
  font-size: 22px; font-weight: 800; color: var(--text); line-height: 1;
}
.score-circle-grade {
  position: relative; z-index: 1;
  font-size: 11px; font-weight: 700; color: var(--text-muted);
}
.score-breakdown { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.score-row { display: flex; flex-direction: column; gap: 3px; }
.score-row-label { font-size: 10px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.score-row-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.score-row-fill { height: 100%; border-radius: 3px; background: var(--primary); transition: width .6s ease; }
.score-row-val { font-size: 11px; font-weight: 700; color: var(--text); }

/* ── AI Panel / Insight Cards ───────────────────────────────────────────────── */
.ai-panel {
  background: linear-gradient(135deg, #faf5ff 0%, #eff6ff 100%);
  border: 1px solid var(--ai-border);
  border-radius: var(--radius); padding: 16px 20px;
}
.ai-panel-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 14px;
}
.ai-badge {
  display: inline-flex; align-items: center; gap: 5px;
  background: linear-gradient(135deg, var(--ai-color), var(--primary-mid));
  color: #fff; font-size: 10px; font-weight: 700; padding: 3px 8px;
  border-radius: 20px; letter-spacing: .05em;
}
.ai-panel-header h3 { font-size: 14px; font-weight: 700; color: var(--text); flex: 1; }

/* Smart Action Items */
.action-list { display: flex; flex-direction: column; gap: 8px; }
.action-item {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px;
  background: var(--bg-white); border-radius: var(--radius-sm);
  border: 1px solid var(--border); transition: box-shadow var(--transition);
}
.action-item:hover { box-shadow: var(--shadow-sm); }
.action-item.critical { border-left: 3px solid var(--danger); }
.action-item.high     { border-left: 3px solid var(--warning); }
.action-item.medium   { border-left: 3px solid var(--primary); }
.action-icon { font-size: 20px; flex-shrink: 0; margin-top: 1px; }
.action-content { flex: 1; min-width: 0; }
.action-content h4 { font-size: 13px; font-weight: 600; color: var(--text); }
.action-content p  { font-size: 11px; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.action-cta { flex-shrink: 0; }

/* Reorder suggestion rows */
.reorder-list { display: flex; flex-direction: column; gap: 6px; }
.reorder-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--bg-white); border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.reorder-item-info { flex: 1; min-width: 0; }
.reorder-item-info strong { font-size: 13px; color: var(--text); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reorder-item-info span   { font-size: 11px; color: var(--text-muted); }
.reorder-item-meta { text-align: right; flex-shrink: 0; }
.reorder-days { font-size: 12px; font-weight: 700; }
.reorder-days.critical { color: var(--danger); }
.reorder-days.low      { color: var(--warning); }

/* ── Filters Bar ────────────────────────────────────────────────────────────── */
.filters-bar {
  display: flex; align-items: center; gap: 8px; margin-bottom: 16px; flex-wrap: wrap;
}
.filters-bar input, .filters-bar select {
  padding: 7px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-white); outline: none; height: 36px; min-width: 150px;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-size: 13px;
}
.filters-bar input:focus,
.filters-bar select:focus { border-color: var(--primary); box-shadow: var(--shadow-glow); }
.filters-bar .search-input { min-width: 220px; }

/* ── Tables ─────────────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--bg-card); border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow-sm); overflow: hidden;
}
.table-wrap table { width: 100%; border-collapse: collapse; }
.table-wrap thead { background: #f8fafc; }
.table-wrap th {
  padding: 10px 14px; text-align: left; font-size: 11px; font-weight: 700;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border); white-space: nowrap; user-select: none;
}
.table-wrap td {
  padding: 11px 14px; font-size: 13px; color: var(--text);
  border-bottom: 1px solid #f1f5f9; vertical-align: middle;
}
.table-wrap tr:last-child td { border-bottom: none; }
.table-wrap tbody tr { transition: background var(--transition); }
.table-wrap tbody tr:hover td { background: #f8f9ff; }
.td-code { font-family: 'Courier New', monospace; font-size: 12px; color: var(--primary); font-weight: 600; }
.td-num  { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.td-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* ── Badges ─────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; padding: 2px 9px;
  border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-blue   { background: #eff6ff; color: #1d4ed8; }
.badge-green  { background: #ecfdf5; color: #065f46; }
.badge-yellow { background: #fffbeb; color: #92400e; }
.badge-red    { background: #fef2f2; color: #991b1b; }
.badge-gray   { background: #f1f5f9; color: #475569; }
.badge-purple { background: #f5f3ff; color: #5b21b6; }
.badge-orange { background: #fff7ed; color: #9a3412; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
  border: none; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all var(--transition); white-space: nowrap;
  letter-spacing: .01em;
}
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }
.btn:active   { transform: translateY(1px); }
.btn-primary  { background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(79,70,229,.3); }
.btn-primary:hover  { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(79,70,229,.35); transform: translateY(-1px); }
.btn-success  { background: var(--success); color: #fff; box-shadow: 0 2px 6px rgba(5,150,105,.3); }
.btn-success:hover  { background: #047857; transform: translateY(-1px); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover   { background: #b91c1c; transform: translateY(-1px); }
.btn-warning  { background: var(--warning); color: #fff; }
.btn-warning:hover  { background: #b45309; }
.btn-secondary{ background: var(--bg-white); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover{ background: var(--bg); border-color: var(--border-dark); }
.btn-outline  { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover  { background: var(--primary-light); }
.btn-ai       { background: linear-gradient(135deg, var(--ai-color), var(--primary-mid)); color: #fff; box-shadow: 0 2px 8px rgba(124,58,237,.3); }
.btn-ai:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(124,58,237,.4); }
.btn-sm  { padding: 5px 12px; font-size: 12px; }
.btn-xs  { padding: 3px 8px; font-size: 11px; }
.btn-icon{ padding: 7px; width: 32px; height: 32px; justify-content: center; }

/* ── Forms ───────────────────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.span-2 { grid-column: span 2; }
.form-group.span-3 { grid-column: span 3; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-muted); letter-spacing: .01em; }
.form-group label .req { color: var(--danger); margin-left: 2px; }
.form-control {
  padding: 9px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  outline: none; width: 100%; background: var(--bg-white); color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  font-size: 13px;
}
.form-control:focus { border-color: var(--primary); box-shadow: var(--shadow-glow); }
.form-control:disabled { background: #f8fafc; color: var(--text-light); cursor: not-allowed; }
.form-control[readonly] { background: #f8fafc; color: var(--text-muted); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 72px; line-height: 1.5; }
.form-hint  { font-size: 11px; color: var(--text-muted); }
.form-error { font-size: 11px; color: var(--danger); }
.form-divider { grid-column: 1/-1; border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(15,23,42,.55); backdrop-filter: blur(3px);
  z-index: 1000; align-items: center; justify-content: center; padding: 16px;
}
.modal-backdrop.show { display: flex; }
.modal-box {
  background: var(--bg-white); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 560px;
  max-height: 92vh; display: flex; flex-direction: column;
  animation: modalIn .2s cubic-bezier(.34,1.56,.64,1);
}
.modal-box.modal-lg { max-width: 780px; }
.modal-box.modal-xl { max-width: 960px; }
.modal-box.modal-sm { max-width: 400px; }
@keyframes modalIn { from { opacity:0; transform: scale(.95) translateY(12px); } to { opacity:1; transform: none; } }
.modal-header {
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; flex-shrink: 0;
}
.modal-header h3 { font-size: 16px; font-weight: 700; flex: 1; color: var(--text); }
.modal-close {
  width: 30px; height: 30px; border: none; background: var(--bg);
  border-radius: var(--radius-sm); font-size: 16px; color: var(--text-muted);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--danger-bg); color: var(--danger); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end; flex-shrink: 0;
}

/* ── Command Palette ─────────────────────────────────────────────────────────── */
.cmd-palette-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(15,23,42,.6); backdrop-filter: blur(4px);
  z-index: 2000; align-items: flex-start; justify-content: center; padding-top: 80px;
}
.cmd-palette-overlay.show { display: flex; }
.cmd-palette {
  background: var(--bg-white); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: min(580px, 92vw);
  animation: modalIn .15s ease; overflow: hidden; border: 1px solid var(--border);
}
.cmd-input-wrap {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.cmd-input-wrap .cmd-icon { font-size: 18px; color: var(--text-muted); flex-shrink: 0; }
#cmdInput {
  flex: 1; border: none; outline: none; font-size: 16px; color: var(--text);
  background: transparent; font-weight: 500;
}
#cmdInput::placeholder { color: var(--text-light); }
.cmd-results { max-height: 340px; overflow-y: auto; }
.cmd-group-label {
  font-size: 10px; font-weight: 700; color: var(--text-muted); letter-spacing: .08em;
  text-transform: uppercase; padding: 10px 18px 4px;
}
.cmd-result {
  display: flex; align-items: center; gap: 12px; padding: 11px 18px;
  cursor: pointer; transition: background var(--transition);
}
.cmd-result:hover, .cmd-result.selected { background: var(--primary-light); }
.cmd-result .cmd-result-icon { font-size: 18px; width: 24px; text-align: center; flex-shrink: 0; }
.cmd-result .cmd-result-label { font-size: 14px; font-weight: 500; color: var(--text); flex: 1; }
.cmd-result .cmd-result-hint  { font-size: 11px; color: var(--text-muted); }
.cmd-footer { padding: 8px 18px; border-top: 1px solid var(--border); display: flex; gap: 12px; background: #fafafa; }
.cmd-footer span { font-size: 11px; color: var(--text-muted); }
.cmd-key { background: var(--border); padding: 1px 5px; border-radius: 4px; font-family: monospace; font-size: 10px; }

/* ── Toast ───────────────────────────────────────────────────────────────────── */
#toastContainer {
  position: fixed; bottom: 80px; right: 20px;
  z-index: 9999; display: flex; flex-direction: column; gap: 8px;
}
.toast {
  min-width: 280px; max-width: 360px; padding: 12px 16px; border-radius: var(--radius);
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px;
  animation: toastIn .25s ease; font-size: 13px; font-weight: 500; color: #fff;
}
@keyframes toastIn { from { opacity:0; transform: translateX(20px); } to { opacity:1; transform: none; } }
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-warning { background: var(--warning); }
.toast-info    { background: var(--info); }

/* ── Line Items Table ────────────────────────────────────────────────────────── */
.line-items-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.line-items-table th {
  font-size: 11px; font-weight: 700; color: var(--text-muted); padding: 7px 8px;
  background: #f8fafc; border: 1px solid var(--border); text-transform: uppercase; letter-spacing: .03em;
}
.line-items-table td { padding: 5px 6px; border: 1px solid var(--border); }
.line-items-table input, .line-items-table select {
  width: 100%; padding: 5px 8px; border: none; outline: none;
  background: transparent; font-size: 12px;
}
.line-items-table input:focus,
.line-items-table select:focus { background: var(--primary-light); border-radius: 2px; }
.btn-del-row { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 15px; padding: 3px; transition: transform var(--transition); }
.btn-del-row:hover { transform: scale(1.2); }

/* ── Dashboard ───────────────────────────────────────────────────────────────── */
.dash-grid   { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.dash-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.dash-grid-ai{ display: grid; grid-template-columns: 320px 1fr; gap: 18px; margin-top: 18px; }
.chart-card { background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border); padding: 20px; }
.chart-card h4 { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 16px; }

/* ── Reports / Tabs ──────────────────────────────────────────────────────────── */
.report-tabs {
  display: flex; gap: 2px; margin-bottom: 16px;
  border-bottom: 2px solid var(--border); overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.report-tabs::-webkit-scrollbar { display: none; }
.report-tab {
  padding: 8px 18px; border: none; background: none; font-size: 13px; font-weight: 600;
  color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: all var(--transition); white-space: nowrap; flex-shrink: 0;
}
.report-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.report-tab:hover:not(.active) { color: var(--text); background: var(--bg); border-radius: var(--radius-xs) var(--radius-xs) 0 0; }

/* ── Alerts ──────────────────────────────────────────────────────────────────── */
.alert-item {
  padding: 14px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  margin-bottom: 8px; display: flex; align-items: flex-start; gap: 12px;
  background: var(--bg-white); transition: box-shadow var(--transition);
}
.alert-item:hover { box-shadow: var(--shadow-sm); }
.alert-item.unread   { border-left: 4px solid var(--primary); }
.alert-item.critical { border-left: 4px solid var(--danger); background: #fff5f5; }
.alert-item.warning  { border-left: 4px solid var(--warning); background: #fffdf5; }
.alert-icon { font-size: 20px; flex-shrink: 0; margin-top: 2px; }
.alert-content h4 { font-size: 13px; font-weight: 600; }
.alert-content p  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.alert-meta { font-size: 11px; color: var(--text-light); margin-top: 4px; }

/* ── Empty State ─────────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: .7; }
.empty-state h3 { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.empty-state p  { font-size: 13px; }

/* ── Skeleton Loading ────────────────────────────────────────────────────────── */
@keyframes shimmer { from { background-position: -400px 0; } to { background-position: 400px 0; } }
.skeleton {
  background: linear-gradient(90deg, #f0f3f8 25%, #e8ecf4 50%, #f0f3f8 75%);
  background-size: 800px 100%; animation: shimmer 1.4s infinite; border-radius: var(--radius-sm);
}
.skeleton-text { height: 14px; margin-bottom: 8px; }
.skeleton-kpi  { height: 80px; border-radius: var(--radius); }

/* ── Mobile Bottom Nav ───────────────────────────────────────────────────────── */
.bottom-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h); background: var(--bg-white);
  border-top: 1px solid var(--border); z-index: 150;
  padding: 0 8px; padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav-inner { display: flex; height: 100%; }
.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; padding: 8px 4px;
  border: none; background: transparent; cursor: pointer;
  font-family: inherit; transition: all var(--transition);
  border-top: 2px solid transparent; color: var(--text-muted);
}
.bottom-nav-item.active { color: var(--primary); border-top-color: var(--primary); }
.bottom-nav-item .bn-icon { font-size: 20px; line-height: 1; }
.bottom-nav-item .bn-label { font-size: 10px; font-weight: 600; letter-spacing: .02em; }

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5);
  z-index: 199; backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

/* ── Utilities ───────────────────────────────────────────────────────────────── */
.flex    { display: flex; }
.gap-2   { gap: 8px; }
.gap-3   { gap: 12px; }
.mt-2    { margin-top: 8px; }
.mt-3    { margin-top: 12px; }
.mt-4    { margin-top: 16px; }
.mb-3    { margin-bottom: 12px; }
.mb-4    { margin-bottom: 16px; }
.ml-auto { margin-left: auto; }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.font-bold   { font-weight: 700; }
.font-mono   { font-family: 'Courier New', monospace; }
.w-100  { width: 100%; }
.hidden { display: none !important; }
.loading { opacity: .6; pointer-events: none; }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Scrollbar ───────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ── AI Chat Widget ──────────────────────────────────────────────────────────── */
#aiChatWidget { position: fixed; bottom: 24px; right: 24px; z-index: 1500; font-family: 'Inter', sans-serif; }

/* Proactive Banner */
#aiProactiveBanner {
  position: fixed; bottom: 90px; right: 24px; width: 320px; z-index: 1490;
  background: var(--bg-white); border: 1px solid var(--ai-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: 12px 14px; animation: modalIn .25s ease;
}
#aiProactiveClose {
  position: absolute; top: 8px; right: 10px; background: none; border: none;
  cursor: pointer; font-size: 14px; color: var(--text-muted);
}
.ai-proactive-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 0;
  font-size: 12px; font-weight: 500; border-bottom: 1px solid var(--border);
}
.ai-proactive-item:last-child { border-bottom: none; }
.ai-proactive-critical { color: var(--danger); }
.ai-proactive-warning  { color: var(--warning); }
.ai-proactive-info     { color: var(--info); }

/* Bubble Button */
#aiChatBubble {
  width: 54px; height: 54px; border-radius: 50%; border: none;
  background: linear-gradient(135deg, var(--ai-color), var(--primary-mid));
  color: #fff; font-size: 22px; font-weight: 700;
  box-shadow: 0 4px 18px rgba(124,58,237,.45);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all var(--transition); position: relative;
}
#aiChatBubble:hover { transform: scale(1.08); box-shadow: 0 6px 24px rgba(124,58,237,.55); }
#aiChatBubble.active { background: linear-gradient(135deg, #6d28d9, var(--primary)); }
#aiUnreadDot {
  position: absolute; top: 4px; right: 4px; width: 12px; height: 12px;
  background: var(--danger); border-radius: 50%; border: 2px solid #fff;
  animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.3)} }

/* Chat Panel */
#aiChatPanel {
  position: fixed; right: 24px; bottom: 90px; width: 380px;
  height: 560px; background: var(--bg-white); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg); border: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  transform: scale(.92) translateY(20px); opacity: 0;
  pointer-events: none; transition: all .25s cubic-bezier(.34,1.56,.64,1);
}
#aiChatPanel.open { transform: none; opacity: 1; pointer-events: all; }

/* Panel Header */
#aiChatHeader {
  background: linear-gradient(135deg, var(--ai-color), var(--primary));
  padding: 14px 16px; display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
#aiChatAvatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255,255,255,.2); display: flex; align-items: center;
  justify-content: center; font-size: 16px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

/* Suggestions Strip */
#aiSuggestStrip {
  border-bottom: 1px solid var(--border); background: #faf5ff; flex-shrink: 0;
}
.ai-suggest-btn {
  width: 100%; text-align: left; background: none; border: 1px solid var(--ai-border);
  border-radius: var(--radius-sm); padding: 7px 10px; font-size: 12px;
  color: var(--ai-color); cursor: pointer; transition: all var(--transition);
  font-family: inherit; font-weight: 500;
}
.ai-suggest-btn:hover { background: var(--ai-bg); border-color: var(--ai-color); }

/* Messages */
#aiMessages {
  flex: 1; overflow-y: auto; padding: 14px; display: flex;
  flex-direction: column; gap: 10px; scroll-behavior: smooth;
}
.ai-msg { display: flex; }
.ai-msg-user      { justify-content: flex-end; }
.ai-msg-assistant { justify-content: flex-start; }
.ai-msg-bubble {
  max-width: 85%; padding: 10px 13px; border-radius: 14px;
  font-size: 13px; line-height: 1.55; position: relative;
}
.ai-msg-user .ai-msg-bubble {
  background: linear-gradient(135deg, var(--primary), var(--primary-mid));
  color: #fff; border-bottom-right-radius: 4px;
}
.ai-msg-assistant .ai-msg-bubble {
  background: #f1f5f9; color: var(--text); border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}
.ai-msg-provider {
  display: block; font-size: 10px; font-weight: 700; margin-top: 5px;
  opacity: .75; letter-spacing: .03em;
}

/* Typing dots */
.ai-typing { display: flex; align-items: center; gap: 5px; padding: 12px 16px !important; }
.ai-typing span {
  width: 7px; height: 7px; background: var(--text-muted); border-radius: 50%;
  animation: typingDot 1.2s infinite;
}
.ai-typing span:nth-child(2) { animation-delay: .2s; }
.ai-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes typingDot { 0%,60%,100%{transform:translateY(0);opacity:.4} 30%{transform:translateY(-6px);opacity:1} }

/* Input */
#aiChatInputWrap {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px;
  border-top: 1px solid var(--border); flex-shrink: 0; background: var(--bg-white);
}
#aiChatInput {
  flex: 1; resize: none; border: 1.5px solid var(--border); border-radius: 20px;
  padding: 8px 14px; font-size: 13px; outline: none; max-height: 120px;
  line-height: 1.4; background: var(--bg); font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}
#aiChatInput:focus { border-color: var(--ai-color); box-shadow: 0 0 0 3px rgba(124,58,237,.15); background: #fff; }
#aiSendBtn {
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: linear-gradient(135deg, var(--ai-color), var(--primary-mid));
  color: #fff; display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; transition: all var(--transition);
  box-shadow: 0 2px 8px rgba(124,58,237,.35);
}
#aiSendBtn:hover  { transform: scale(1.1); }
#aiSendBtn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* Provider Status Modal */
#aiProviderModal {
  position: fixed; inset: 0; background: rgba(15,23,42,.5); backdrop-filter: blur(3px);
  z-index: 2100; display: none; align-items: center; justify-content: center; padding: 16px;
}
#aiProviderModal[style*="flex"] { display: flex !important; }
#aiProviderModalBox {
  background: var(--bg-white); border-radius: var(--radius-lg);
  padding: 20px; width: min(360px, 92vw); box-shadow: var(--shadow-lg);
  animation: modalIn .2s ease;
}

/* Mobile */
@media (max-width: 768px) {
  #aiChatPanel {
    right: 0; bottom: 0; width: 100%; height: 70vh; border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-bottom: none;
  }
  #aiChatWidget { bottom: calc(var(--bottom-nav-h) + 10px); right: 16px; }
  #aiProactiveBanner { right: 12px; bottom: calc(var(--bottom-nav-h) + 76px); width: calc(100% - 24px); }
  #aiChatPanel.open { bottom: var(--bottom-nav-h); }
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .dash-grid-ai { grid-template-columns: 1fr; }
  .cmd-bar { max-width: 200px; min-width: 160px; }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 256px; --header-h: 56px; }

  .sidebar {
    transform: translateX(-100%); transition: transform var(--transition);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .header { left: 0; }
  .main-content {
    margin-left: 0;
    padding: 16px;
    padding-bottom: calc(var(--bottom-nav-h) + 16px);
  }

  .hamburger-btn { display: flex; }
  .cmd-bar { display: none; }
  .user-info { display: none; }
  .header-tenant { display: none; }
  .logout-btn { display: none; }

  .bottom-nav { display: block; }
  #toastContainer { bottom: calc(var(--bottom-nav-h) + 12px); right: 12px; }

  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-value { font-size: 22px; }
  .dash-grid, .dash-grid-3, .dash-grid-ai { grid-template-columns: 1fr; }

  .modal-box { max-width: 100%; border-radius: var(--radius) var(--radius) 0 0; }
  .modal-backdrop { align-items: flex-end; padding: 0; }

  .form-grid-2 { grid-template-columns: 1fr; }
  .form-group.span-2 { grid-column: span 1; }
  .form-grid-3 { grid-template-columns: 1fr 1fr; }

  /* Table → card view on mobile */
  .table-wrap.mobile-cards table,
  .table-wrap.mobile-cards thead,
  .table-wrap.mobile-cards tbody,
  .table-wrap.mobile-cards th,
  .table-wrap.mobile-cards td,
  .table-wrap.mobile-cards tr { display: block; }
  .table-wrap.mobile-cards thead { display: none; }
  .table-wrap.mobile-cards tbody tr {
    padding: 12px 14px; border-bottom: 1px solid var(--border); position: relative;
  }
  .table-wrap.mobile-cards tbody tr:last-child { border-bottom: none; }
  .table-wrap.mobile-cards td {
    padding: 3px 0; border: none; display: flex; gap: 8px; align-items: flex-start;
  }
  .table-wrap.mobile-cards td::before {
    content: attr(data-label);
    font-size: 10px; font-weight: 700; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .04em; min-width: 88px; flex-shrink: 0; padding-top: 1px;
  }

  .page-header h1 { font-size: 17px; }
  .report-tabs { gap: 0; }
  .report-tab  { padding: 8px 12px; font-size: 12px; }
}

@media (max-width: 420px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .btn-xs .btn-label { display: none; }
}
