/* ── Reset & Variables ──────────────────────────────────────────────────── */
:root {
  --bg:        #0d1117;
  --bg2:       #161b22;
  --bg3:       #1c2128;
  --bg4:       #22272e;
  --border:    #30363d;
  --border2:   #3d4450;
  --text:      #e6edf3;
  --muted:     #8b949e;
  --primary:   #2f81f7;
  --primary-h: #1f6feb;
  --success:   #3fb950;
  --warning:   #d29922;
  --danger:    #f85149;
  --online:    #3fb950;
  --offline:   #484f58;
  --radius:    6px;
  --radius-lg: 10px;
  --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --topbar-h:  52px;
  --sidebar-w: 220px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; font-size: 14px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; }

/* ── Auth Screens ──────────────────────────────────────────────────────── */
.auth-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: var(--bg);
}
.auth-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 36px 32px; width: 380px;
}
.auth-logo { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.auth-logo-icon {
  width: 42px; height: 42px; border-radius: 10px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; flex-shrink: 0;
}
.auth-logo-title { font-size: 18px; font-weight: 700; }
.auth-logo-sub   { font-size: 12px; color: var(--muted); margin-top: 2px; }
.auth-hint       { font-size: 13px; color: var(--muted); text-align: center; margin-top: 16px; }

/* ── Form Fields ────────────────────────────────────────────────────────── */
.field-group  { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-label  { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.field-input  {
  padding: 8px 12px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 14px; outline: none;
  width: 100%; transition: border-color 0.15s; font-family: var(--font);
}
.field-input:focus { border-color: var(--primary); }
.field-row    { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
textarea.field-input { resize: vertical; min-height: 80px; }
.select-input {
  padding: 6px 10px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 13px; outline: none;
}
.select-input:focus { border-color: var(--primary); }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius); border: 1px solid transparent;
  font-size: 13px; font-weight: 500; white-space: nowrap; transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-h); border-color: var(--primary-h); }
.btn-danger  { background: rgba(248,81,73,.15); color: var(--danger); border-color: rgba(248,81,73,.3); }
.btn-danger:hover  { background: rgba(248,81,73,.25); }
.btn-ghost   { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover   { background: var(--bg3); color: var(--text); }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--bg3); }
.btn-full    { width: 100%; justify-content: center; }
.btn-lg      { padding: 10px 18px; font-size: 14px; }
.btn-small   { padding: 4px 10px; font-size: 12px; }
.btn-icon    { padding: 6px; border-radius: var(--radius); }

/* ── Alerts ─────────────────────────────────────────────────────────────── */
.alert-error {
  background: rgba(248,81,73,.1); border: 1px solid rgba(248,81,73,.3);
  color: var(--danger); padding: 10px 14px; border-radius: var(--radius);
  font-size: 13px; margin-bottom: 14px;
}

/* ── Topbar ─────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h); background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; flex-shrink: 0; z-index: 100; position: relative;
}
.topbar-left  { display: flex; align-items: center; gap: 24px; }
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.topbar-brand-icon {
  width: 28px; height: 28px; border-radius: 6px; background: var(--primary);
  color: #fff; font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.topbar-brand-name { font-size: 15px; font-weight: 600; }
.topbar-nav   { display: flex; gap: 2px; }
.topbar-nav-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--radius); border: none;
  background: transparent; color: var(--muted); font-size: 13px; font-weight: 500;
  transition: all 0.15s; position: relative;
}
.topbar-nav-btn:hover { background: var(--bg3); color: var(--text); }
.topbar-nav-btn.active { background: rgba(47,129,247,.12); color: var(--primary); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-badge {
  background: var(--danger); color: #fff; border-radius: 10px;
  font-size: 10px; font-weight: 700; padding: 1px 5px; min-width: 16px; text-align: center;
}
.topbar-alert {
  display: flex; align-items: center; gap: 5px;
  background: rgba(210,153,34,.12); color: var(--warning);
  border: 1px solid rgba(210,153,34,.25); border-radius: var(--radius);
  padding: 4px 10px; font-size: 12px; font-weight: 600;
}
.topbar-icon-btn {
  width: 32px; height: 32px; border-radius: var(--radius);
  background: transparent; border: none; color: var(--muted);
  display: flex; align-items: center; justify-content: center; transition: all 0.15s;
}
.topbar-icon-btn:hover { background: var(--bg3); color: var(--text); }

/* ── App Layout ─────────────────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; height: 100vh; }
.app-body { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
  overflow: hidden;
}
.sidebar-search-wrap {
  position: relative; padding: 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar-search-icon {
  position: absolute; left: 18px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}
.sidebar-search {
  width: 100%; padding: 6px 10px 6px 28px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 13px; outline: none;
}
.sidebar-search:focus { border-color: var(--primary); }
.agent-tree { flex: 1; overflow-y: auto; padding: 6px 0; }

/* Tree groups */
.tree-group-label {
  padding: 8px 12px 4px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted);
  display: flex; align-items: center; justify-content: space-between;
}
.tree-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; cursor: pointer; border-radius: 0;
  font-size: 13px; color: var(--muted); transition: all 0.1s;
  border-left: 2px solid transparent;
}
.tree-item:hover  { background: var(--bg3); color: var(--text); }
.tree-item.active { background: rgba(47,129,247,.1); color: var(--primary); border-left-color: var(--primary); }
.status-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
  background: var(--offline);
}
.status-dot.online { background: var(--online); box-shadow: 0 0 4px var(--online); }
.tree-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-item-os   { font-size: 11px; color: var(--muted); }

/* ── Main ───────────────────────────────────────────────────────────────── */
.main { flex: 1; overflow-y: auto; overflow-x: hidden; }

/* ── Pages ──────────────────────────────────────────────────────────────── */
.page { padding: 24px; max-width: 1300px; }
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 24px;
}
.page-title { font-size: 20px; font-weight: 700; }
.page-sub   { font-size: 13px; color: var(--muted); margin-top: 3px; }
.page-header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ── Overview Cards ─────────────────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.device-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px; cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}
.device-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.device-card-head  { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.device-card-icon  {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--bg3); display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.device-card-title  { font-weight: 600; font-size: 14px; }
.device-card-sub    { font-size: 12px; color: var(--muted); margin-top: 2px; }
.mini-bar-row       { display: flex; flex-direction: column; gap: 5px; }
.mini-bar-item      { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.mini-bar-label     { width: 32px; color: var(--muted); font-weight: 500; }
.mini-bar-track     { flex: 1; height: 4px; background: var(--bg4); border-radius: 2px; }
.mini-bar-fill      { height: 100%; border-radius: 2px; background: var(--primary); transition: width 0.5s; }
.mini-bar-fill.warn { background: var(--warning); }
.mini-bar-fill.crit { background: var(--danger); }
.mini-bar-val       { width: 32px; text-align: right; color: var(--muted); }

/* ── Companies List ─────────────────────────────────────────────────────── */
.companies-list { display: flex; flex-direction: column; gap: 12px; }
.company-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
}
.company-card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; cursor: pointer;
  transition: background 0.15s;
}
.company-card-head:hover { background: var(--bg3); }
.company-card-head-left { display: flex; align-items: center; gap: 14px; }
.company-avatar {
  width: 40px; height: 40px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.company-name    { font-size: 15px; font-weight: 600; }
.company-email   { font-size: 12px; color: var(--muted); margin-top: 2px; }
.company-stats   { display: flex; gap: 16px; }
.company-stat    { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); }
.company-stat svg { flex-shrink: 0; }
.company-actions { display: flex; gap: 6px; }
.company-body {
  border-top: 1px solid var(--border); padding: 16px 20px;
  display: none;
}
.company-body.open { display: block; }
.company-section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 10px; }
.agent-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.agent-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 10px; font-size: 12px;
}

/* ── Tickets ────────────────────────────────────────────────────────────── */
.tickets-board { display: flex; flex-direction: column; gap: 8px; }
.ticket-row {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  display: grid;
  grid-template-columns: 3fr 1.5fr 1.5fr 1.5fr 100px 100px 140px;
  align-items: center; gap: 12px;
  transition: border-color 0.15s;
}
.ticket-row:hover { border-color: var(--border2); }
.ticket-row-header {
  display: grid;
  grid-template-columns: 3fr 1.5fr 1.5fr 1.5fr 100px 100px 140px;
  gap: 12px; padding: 6px 16px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted);
}
.ticket-title-cell .ticket-subject { font-weight: 500; font-size: 14px; }
.ticket-title-cell .ticket-id      { font-size: 11px; color: var(--muted); margin-top: 2px; }
.priority-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 5px; }
.p-low      { background: var(--muted); }
.p-normal   { background: var(--primary); }
.p-high     { background: var(--warning); }
.p-critical { background: var(--danger); }
.status-pill {
  padding: 3px 9px; border-radius: 12px; font-size: 11px; font-weight: 600; white-space: nowrap;
}
.s-open        { background: rgba(47,129,247,.12); color: var(--primary); }
.s-in_progress { background: rgba(210,153,34,.12); color: var(--warning); }
.s-closed      { background: var(--bg3); color: var(--muted); }
.ticket-actions { display: flex; gap: 4px; }

/* ── Agent Detail ───────────────────────────────────────────────────────── */
.online-badge {
  padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 600;
}
.online-badge.online  { background: rgba(63,185,80,.12); color: var(--online); }
.online-badge.offline { background: var(--bg3); color: var(--muted); }

/* Tabs */
.tab-bar { display: flex; gap: 2px; border-bottom: 1px solid var(--border); padding: 0 24px; }
.tab {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 14px; background: none; border: none;
  color: var(--muted); font-size: 13px; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: all 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-pane { padding: 24px; }

/* KPI Cards */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px,1fr)); gap: 12px; margin-bottom: 20px; }
.kpi-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; }
.kpi-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 8px; }
.kpi-value { font-size: 26px; font-weight: 700; margin-bottom: 10px; }
.kpi-bar   { height: 5px; background: var(--bg4); border-radius: 3px; }
.kpi-bar-fill { height: 100%; border-radius: 3px; background: var(--primary); transition: width 0.5s, background 0.5s; }

/* Charts */
.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.chart-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; }
.chart-card-title { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.04em; }

/* Toolbar */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar-label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.toolbar-status { font-size: 12px; color: var(--muted); }

/* Terminal */
.terminal-wrap {
  background: #0d1117; border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 10px; height: 480px;
}

/* Desktop */
.desktop-wrap {
  background: #000; border: 1px solid var(--border);
  border-radius: var(--radius); overflow: auto; cursor: crosshair;
  max-width: 100%;
}
.desktop-canvas { display: block; max-width: 100%; }

/* Table */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; padding: 9px 14px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  color: var(--muted); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap;
}
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.data-table tbody tr:hover td { background: var(--bg2); }
.section-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin: 20px 0 10px; }

/* ── Modals ─────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 500;
}
.modal-box {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto; padding: 24px;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px;
}
.modal-head h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  width: 28px; height: 28px; border-radius: var(--radius);
  background: transparent; border: none; color: var(--muted);
  font-size: 16px; display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.modal-close:hover { background: var(--bg3); color: var(--text); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Enduser List ───────────────────────────────────────────────────────── */
.eu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.eu-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg4); display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0; color: var(--primary);
}
.eu-info { flex: 1; }
.eu-name  { font-size: 13px; font-weight: 500; }
.eu-email { font-size: 12px; color: var(--muted); }

/* ── Toasts ─────────────────────────────────────────────────────────────── */
.toast-stack { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
  font-size: 13px; min-width: 260px; max-width: 380px;
  animation: slideUp 0.2s ease;
}
.toast.success { border-color: rgba(63,185,80,.4); color: var(--success); }
.toast.warning { border-color: rgba(210,153,34,.4); }
.toast.danger  { border-color: rgba(248,81,73,.4);  color: var(--danger); }
@keyframes slideUp { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Misc ───────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.empty  { text-align: center; padding: 40px; color: var(--muted); font-size: 14px; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

@media (max-width: 900px) {
  .sidebar { width: 180px; }
  .chart-row { grid-template-columns: 1fr; }
  .ticket-row, .ticket-row-header { grid-template-columns: 1fr; }
}

/* ── Settings ────────────────────────────────────────────────────────────── */
.settings-section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 20px;
}
.settings-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.settings-section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
  margin: 0;
}
