/* ============================
   CSS VARIABLES & RESET
   ============================ */
:root {
  --bg-page:          #F2F2F2;
  --bg-card:          #FFFFFF;
  --bg-topbar:        #FFFFFF;
  --bg-hover:         #F8F8F8;
  --text-primary:     #1A1A1A;
  --text-muted:       #6B6B6B;
  --border:           #E0E0E0;
  --shadow:           0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:        0 4px 12px rgba(0,0,0,0.10);
  --shadow-lg:        0 8px 24px rgba(0,0,0,0.12);
  --radius:           8px;
  --radius-sm:        4px;
  --radius-lg:        12px;

  --red:              #B01A18;
  --red-hover:        #8B1210;
  --navy:             #1B3A6B;
  --green:            #2D7A55;
  --amber:            #B87A14;
  --danger:           #C0181E;

  --sidebar-bg:       #151920;
  --sidebar-text:     #9aa3b2;
  --sidebar-active-text: #E84444;
  --sidebar-active-bg:   rgba(176,26,24,0.12);
  --sidebar-hover-bg:    rgba(255,255,255,0.05);
  --sidebar-label:    #6b7482;
  --sidebar-width:    220px;
  --topbar-height:    56px;

  --transition:       0.15s ease;
}

[data-theme="dark"] {
  --bg-page:          #0e1014;
  --bg-card:          #151920;
  --bg-topbar:        #151920;
  --bg-hover:         #1b2029;
  --text-primary:     #e6e9ef;
  --text-muted:       #9aa3b2;
  --border:           #262c37;
  --shadow:           0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:        0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg:        0 8px 24px rgba(0,0,0,0.6);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 12px; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-primary);
  background: var(--bg-page);
  line-height: 1.5;
  transition: background var(--transition), color var(--transition);
}

a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ============================
   APP SHELL
   ============================ */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ============================
   SIDEBAR
   ============================ */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  transition: transform 0.25s ease, width 0.25s ease;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 14px 10px 14px 12px; /* room for logo + brand text beside the collapse button */
  border-bottom: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 64px;
  flex-shrink: 0;
}

/* Brand block: CTI logo, then name over subtitle. Same rules in Athena's core/style.css. */
.sidebar-brand {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
}
.brand-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
}
.brand-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  overflow: hidden;
}
.brand-label {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.01em;
  color: #B01A18;
  text-transform: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-name {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--sidebar-text, #aaa);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Collapse toggle */
.sidebar-collapse-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: var(--sidebar-label, #555);
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.sidebar-collapse-btn:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
  border-color: rgba(255,255,255,0.25);
}
.collapse-chevron { transition: transform 0.25s ease; }

.sidebar-nav {
  padding: 12px 0;
  flex: 1;
  overflow-y: auto;
}

/* ── Sidebar user footer ─────────────────── */
.sidebar-user-footer {
  padding: 10px 12px;
  border-top: 1px solid rgba(255,255,255,0.07);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1;
  min-width: 0;
}
.sidebar-user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-user-details { min-width: 0; flex: 1; }
.sidebar-user-name {
  font-size: 12px;
  font-weight: 600;
  color: #ddd;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 10px;
  color: var(--sidebar-label);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-logout-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: var(--sidebar-label);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.sidebar-logout-btn:hover {
  background: rgba(176,26,24,0.2);
  color: #ff6b6b;
  border-color: rgba(176,26,24,0.4);
}

/* ── Nav links ─────────────────────────── */
.nav-section-label {
  padding: 10px 16px 4px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sidebar-label);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px 9px 13px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--sidebar-text);
  border-left: 3px solid transparent;
  text-decoration: none;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.nav-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity var(--transition);
}
.nav-link:hover .nav-icon,
.nav-link.active .nav-icon { opacity: 1; }
.nav-text { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; }
.nav-arrow {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.45;
  transition: transform 0.2s ease, opacity var(--transition);
}
.nav-link.open .nav-arrow { transform: rotate(90deg); opacity: 0.7; }

.nav-link:hover {
  background: var(--sidebar-hover-bg);
  color: #FFFFFF;
}
.nav-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  border-left-color: var(--red);
}
.nav-link.has-sub.active {
  background: rgba(176,26,24,0.08);
  color: #fff;
  border-left-color: var(--red);
}

/* ── Submenu ───────────────────────────── */
.nav-submenu {
  display: none;
  flex-direction: column;
  background: rgba(0,0,0,0.18);
  border-left: 3px solid rgba(176,26,24,0.3);
  margin-left: 0;
}
.nav-submenu.open { display: flex; }
.nav-sub-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 8px 32px;
  font-size: 12px;
  font-weight: 400;
  color: #888;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
  white-space: nowrap;
  border-left: none;
}
.nav-sub-link:hover { background: rgba(255,255,255,0.04); color: #ccc; }
.nav-sub-link.active { color: #E84444; font-weight: 600; }
.nav-sub-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
  opacity: 0.6;
}
.nav-sub-link.active .nav-sub-dot { opacity: 1; }

/* ── Collapsed sidebar ─────────────────── */
.sidebar.collapsed { width: 54px; min-width: 54px; }
.sidebar.collapsed .sidebar-brand { display: none; }
.sidebar.collapsed .sidebar-header { justify-content: center; padding: 14px 0; }
.sidebar.collapsed .collapse-chevron { transform: rotate(180deg); }
.sidebar.collapsed .nav-link {
  justify-content: center;
  padding: 10px 0;
  border-left: none;
  border-right: 3px solid transparent;
}
.sidebar.collapsed .nav-link.active {
  border-left: none;
  border-right-color: var(--red);
}
.sidebar.collapsed .nav-text { display: none; }
.sidebar.collapsed .nav-arrow { display: none; }
.sidebar.collapsed .nav-icon { opacity: 0.65; }
.sidebar.collapsed .nav-link:hover .nav-icon { opacity: 1; }
.sidebar.collapsed .nav-section-label { display: none; }
.sidebar.collapsed .nav-submenu { display: none !important; }
.sidebar.collapsed .sidebar-user-details { display: none; }
.sidebar.collapsed .sidebar-user-info { flex: 0 0 auto; }
.sidebar.collapsed .sidebar-user-footer { justify-content: center; padding: 10px 0; }
.sidebar.collapsed .sidebar-logout-btn { display: none; }
.sidebar.collapsed .ctisign-open-btn { display: none; }

/* ── Nav divider ──────────────────────────── */
.nav-divider {
  height: 1px;
  background: rgba(255,255,255,0.10);
  margin: 6px 10px;
}

/* ── CTI Sign nav item — same format as every other nav-link, branded red ── */
.ctisign-nav {
  color: var(--red);
  gap: 10px;
}
.ctisign-nav:hover {
  background: rgba(176,26,24,0.10);
  color: var(--sidebar-active-text);
}
.ctisign-logo-wrap {
  width: 15px;
  height: 15px;
  min-width: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.9;
}
.ctisign-logo {
  width: 17px;
  height: 17px;
}
.ctisign-text-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  overflow: hidden;
}
.ctisign-title {
  font-size: 12.5px;
  font-weight: 600;
  color: inherit;
  line-height: 1.3;
  white-space: nowrap;
}
.ctisign-open-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: var(--sidebar-label);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: auto;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.ctisign-nav:hover .ctisign-open-btn {
  background: rgba(176,26,24,0.2);
  color: var(--sidebar-active-text);
  border-color: rgba(176,26,24,0.4);
}
.ctisign-desc {
  font-size: 10px;
  font-weight: 500;
  color: var(--sidebar-label);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* ============================
   MAIN WRAPPER
   ============================ */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ============================
   TOPBAR
   ============================ */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition);
  z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.hamburger {
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  border-radius: var(--radius-sm);
}
.hamburger span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: background var(--transition);
}
.hamburger:hover span { background: var(--red); }
.topbar-breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.breadcrumb-app { color: var(--text-muted); font-weight: 400; }
.breadcrumb-sep { color: var(--border); }
.breadcrumb-page { color: var(--text-primary); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-date { font-size: 12px; color: var(--text-muted); }

/* Theme Toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0;
  overflow: hidden;
  font-size: 12px;
  font-weight: 500;
}
.theme-toggle-light, .theme-toggle-dark {
  padding: 4px 10px;
  border-radius: 20px;
  transition: background var(--transition), color var(--transition);
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
[data-theme="light"] .theme-toggle-light { background: var(--text-primary); color: #FFFFFF; }
[data-theme="dark"]  .theme-toggle-dark  { background: var(--text-primary); color: var(--bg-card); }

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--red);
  color: #FFFFFF;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.user-chip { display: flex; align-items: center; gap: 7px; }
.user-chip-name { font-size: 12px; font-weight: 600; color: var(--text-primary); white-space: nowrap; }
@media (max-width: 600px) { .user-chip-name { display: none; } }

/* ============================
   MAIN CONTENT
   ============================ */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  transition: opacity var(--transition);
}
.main-footer {
  padding: 12px 24px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--bg-topbar);
  flex-shrink: 0;
}

/* ============================
   PAGE HEADER
   ============================ */
.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 16px; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.page-header .subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.division-header { border-left: 4px solid var(--red); padding-left: 12px; }

/* ============================
   CARDS
   ============================ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-title { font-size: 14px; font-weight: 600; color: var(--text-primary); margin-bottom: 16px; }
.card-subtitle { font-size: 12px; color: var(--text-muted); margin-top: -12px; margin-bottom: 14px; }

/* ============================
   KPI CARDS
   ============================ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition), background var(--transition), border-color var(--transition);
}
.kpi-card:hover { box-shadow: var(--shadow-md); }
.kpi-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
.kpi-value {
  display: block;
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 6px;
}

/* ============================
   TABLES
   ============================ */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: var(--bg-page);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }
tbody td { padding: 10px 14px; color: var(--text-primary); vertical-align: middle; }
.td-muted { color: var(--text-muted); font-size: 12px; }

/* ============================
   BADGES
   ============================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge--active     { background: rgba(45,122,85,0.12);   color: var(--green); }
.badge--pending    { background: rgba(184,122,20,0.12);  color: var(--amber); }
.badge--complete   { background: rgba(45,122,85,0.12);   color: #1E5C38; }
.badge--failed     { background: rgba(176,26,24,0.12);   color: var(--red); }

/* ============================
   BUTTONS
   ============================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  border: 1px solid transparent;
}
.btn-primary { background: var(--red); color: #FFFFFF; border-color: var(--red); }
.btn-primary:hover { background: var(--red-hover); border-color: var(--red-hover); }
.btn-secondary { background: var(--bg-card); color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--red); color: var(--red); }
.btn-sm { padding: 4px 10px; font-size: 11px; font-weight: 500; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-card); color: var(--text-primary); transition: all var(--transition); }
.btn-sm:hover { border-color: var(--red); color: var(--red); }

/* ============================
   FILTER BAR
   ============================ */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.filter-search {
  flex: 1; min-width: 200px; max-width: 320px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}
.filter-search:focus { border-color: var(--red); }

/* ============================
   EMPTY STATE
   ============================ */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state-icon { font-size: 40px; margin-bottom: 12px; opacity: 0.4; }
.empty-state h3 { font-size: 15px; font-weight: 600; color: var(--text-primary); margin-bottom: 4px; }
.empty-state p { font-size: 13px; }

/* ============================
   TOAST
   ============================ */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 500; display: flex; flex-direction: column; gap: 8px; }
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: #151920; color: #FFFFFF;
  border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  min-width: 240px;
  animation: toastIn 0.25s ease;
  border-left: 3px solid var(--green);
}
.toast.error { border-left-color: var(--danger); }
.toast.info  { border-left-color: var(--navy); }
.toast.out   { animation: toastOut 0.25s ease forwards; }
@keyframes toastIn  { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(5px); } }

/* ============================
   SECTION CONTENT PANELS
   ============================ */
.content-panel { display: none; }
.content-panel.active { display: block; }

/* ============================
   DOCUMENT UPLOAD ZONE
   ============================ */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 24px;
  text-align: center;
  color: var(--text-muted);
  transition: border-color var(--transition), background var(--transition);
  cursor: pointer;
}
.upload-zone:hover {
  border-color: var(--red);
  background: rgba(176,26,24,0.03);
  color: var(--red);
}
.upload-zone-icon { font-size: 36px; margin-bottom: 12px; opacity: 0.5; }
.upload-zone h3 { font-size: 15px; font-weight: 600; color: var(--text-primary); margin-bottom: 4px; }
.upload-zone p { font-size: 13px; }

/* ============================
   ZOHO STATUS BADGE
   ============================ */
.zoho-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.zoho-badge.connected { background: rgba(45,122,85,0.12); color: var(--green); }
.zoho-badge.disconnected { background: rgba(192,24,30,0.10); color: var(--danger); }
.zoho-badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ============================
   MISC
   ============================ */
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.text-muted { color: var(--text-muted); font-size: 12px; }
.text-red { color: var(--red); }
.section-title { font-size: 16px; font-weight: 700; color: var(--text-primary); margin-bottom: 14px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================
   RESPONSIVE
   ============================ */
@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    transform: translateX(-100%);
    z-index: 100;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.active { display: block; }
  .main-wrapper { width: 100%; }
  .hamburger { display: flex; }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .main-content { padding: 16px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .topbar-date { display: none; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

/* Top-bar "Pull Data": Inter sits the label a touch low in its 26px pill; lift it 1px so it
   lines up with the icon and the Server Live badge (matches eSign). */
#refreshBtn .pull-label { position: relative; top: -1px; }
