/* =====================================================================
   Operation Hub - Stylesheet
   Fixes for: bottom-of-tab visual issues, sidebar overlap with content,
   footer placement, scroll padding, table overflow, modal layout
   ===================================================================== */

* { margin: 0; padding: 0; box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-soft: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --sidebar-bg: linear-gradient(180deg, #1e3a5f 0%, #0f2847 100%);
  --sidebar-w: 240px;
  --header-h: 0px;
  --footer-h: 48px;
}
html, body { height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }

.hidden { display: none !important; }

/* ============================== AUTH ============================== */
.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--sidebar-bg); padding: 24px;
}
.auth-card {
  width: 100%; max-width: 420px; background: #fff; border-radius: 16px;
  padding: 40px 32px; box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.auth-brand { text-align: center; margin-bottom: 32px; }
.auth-logo {
  width: 56px; height: 56px; border-radius: 14px; margin: 0 auto 12px;
  background: var(--sidebar-bg); color: #fff; font-weight: 700; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
}
.auth-brand h1 { font-size: 22px; }
.auth-brand p { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.auth-card h2 { font-size: 18px; margin-bottom: 8px; }
.auth-subtitle { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; line-height: 1.5; }
.auth-info-line { font-size: 13px; margin-bottom: 8px; }
.auth-footnote { font-size: 12px; color: var(--text-muted); margin-top: 20px; line-height: 1.5; padding-top: 16px; border-top: 1px solid var(--border-soft); }
.auth-icon-warning, .auth-icon-error {
  width: 60px; height: 60px; border-radius: 50%; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center; font-size: 28px;
}
.auth-icon-warning { background: #fef3c7; color: #92400e; }
.auth-icon-error { background: #fee2e2; color: #991b1b; }
.btn-google {
  width: 100%; padding: 12px 16px; background: #fff; border: 1px solid var(--border);
  border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14px;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  transition: all 0.15s;
}
.btn-google:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; padding: 8px; margin-top: 8px; }

/* ============================== APP SHELL ============================== */
.app { display: flex; min-height: 100vh; }

/* Sidebar — fixed, full height, internal scroll */
.sidebar {
  width: var(--sidebar-w); background: var(--sidebar-bg); color: #fff;
  position: fixed; top: 0; left: 0; height: 100vh;
  display: flex; flex-direction: column;
  /* Important: allow nav scroll without pushing user-info */
}
.brand { padding: 24px; border-bottom: 1px solid rgba(255,255,255,0.08); flex-shrink: 0; }
.brand h1 { font-size: 16px; font-weight: 700; letter-spacing: 0.5px; }
.brand p { font-size: 11px; opacity: 0.7; margin-top: 4px; }

/* Nav: scrollable middle area; takes all leftover vertical space */
nav#navList {
  flex: 1; overflow-y: auto; padding: 12px 0;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 24px; cursor: pointer; transition: all 0.15s;
  font-size: 14px; border-left: 3px solid transparent; color: rgba(255,255,255,0.85);
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: #fff; }
.nav-item.active { background: rgba(59,130,246,0.18); border-left-color: var(--primary); color: #93c5fd; }
.nav-item .icon { font-size: 16px; width: 20px; text-align: center; opacity: 0.85; }

/* User info: pinned at bottom inside sidebar flex column */
.user-info {
  flex-shrink: 0; padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.18);
  display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255,255,255,0.1); object-fit: cover;
}
.user-meta { flex: 1; min-width: 0; }
.user-meta .name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta .role { font-size: 11px; opacity: 0.7; }
.btn-icon {
  background: rgba(255,255,255,0.05); color: #fff; border: 1px solid rgba(255,255,255,0.1);
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.btn-icon:hover { background: rgba(255,255,255,0.12); }

/* Main: offset by sidebar, with bottom padding to clear footer */
.main {
  flex: 1; margin-left: var(--sidebar-w);
  display: flex; flex-direction: column; min-height: 100vh;
  padding: 24px 32px 0; /* Bottom padding handled by .page-footer spacing */
}

/* Sync banner */
.sync-banner {
  background: #eff6ff; color: #1e40af; padding: 8px 16px; border-radius: 8px;
  font-size: 12px; margin-bottom: 16px;
}

/* Page container — flex grow so footer stays at bottom */
#pageContainer { flex: 1; padding-bottom: 32px; }

/* Footer — sticks to bottom of main, never overlaps tab content */
.page-footer {
  margin-top: auto; padding: 14px 0;
  border-top: 1px solid var(--border-soft);
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; color: var(--text-muted);
  background: var(--bg);
}

/* ============================== PAGE LAYOUT ============================== */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Buttons */
.btn { padding: 8px 16px; border-radius: 8px; border: none; cursor: pointer; font-size: 13px; font-weight: 600; transition: all 0.15s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: #475569; border: 1px solid var(--border); }
.btn-secondary:hover { background: #f8fafc; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Cards */
.card { background: var(--surface); border-radius: 12px; padding: 18px 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.04); border: 1px solid var(--border-soft); }
.card-title { font-size: 13px; font-weight: 700; color: var(--text); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border-soft); }

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

/* Stat cards */
.stat-card { padding: 16px 18px; }
.stat-card .label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.stat-card .value { font-size: 24px; font-weight: 700; color: var(--text); margin-top: 6px; line-height: 1.2; }
.stat-card .sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.stat-card.stat-warn { border-left: 3px solid var(--warn); }
.stat-card.stat-danger { border-left: 3px solid var(--danger); }
.big-num { font-size: 32px; font-weight: 700; color: var(--text); margin-top: 8px; }

/* Live dot */
.live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--success); margin-right: 6px; vertical-align: middle; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{ opacity: 1 } 50%{ opacity: 0.4 } }

/* Date/period range */
.date-range { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.date-range select, .date-range input {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px;
}

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap table { width: 100%; border-collapse: collapse; min-width: 600px; }
table th { text-align: left; padding: 10px 12px; font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; font-weight: 600; border-bottom: 2px solid var(--border); background: #f8fafc; white-space: nowrap; }
table td { padding: 10px 12px; font-size: 13px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
table tr:last-child td { border-bottom: none; }
table tr:hover td { background: #f8fafc; }
table .num { text-align: right; font-variant-numeric: tabular-nums; }
table .empty { text-align: center; color: var(--text-muted); padding: 32px 16px; }

/* Sub-tabs */
.sub-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.sub-tab { padding: 10px 16px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; white-space: nowrap; transition: color 0.15s; }
.sub-tab:hover { color: var(--text); }
.sub-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.subpage-actions { display: flex; justify-content: flex-end; margin-bottom: 12px; }

/* Status badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-purple  { background: #ede9fe; color: #6b21a8; }
.badge-gray    { background: #f1f5f9; color: #475569; }

/* Form */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: #475569; margin-bottom: 6px; }
.form-control { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; transition: border-color 0.15s; background: #fff; }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }
.form-control.inline { display: inline-block; width: auto; padding: 4px 8px; font-size: 12px; }

/* Actions row */
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--text-muted); font-size: 12px; line-height: 1.6; }

/* Chart wrap — REMOVED extra padding/margin issues at bottom */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { max-width: 100% !important; }

/* Permissions table inside modal */
.perm-table { width: 100%; border-collapse: collapse; }
.perm-table th, .perm-table td { padding: 8px; text-align: left; border-bottom: 1px solid var(--border-soft); font-size: 13px; }

/* ============================== MODAL ============================== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 999;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal-card {
  background: #fff; border-radius: 12px; width: 100%; max-width: 600px;
  max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border-soft); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 16px; }
.modal-header .btn-icon { background: var(--border-soft); color: var(--text); border: none; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border-soft); display: flex; justify-content: flex-end; gap: 8px; background: #f8fafc; }

/* ============================== TOAST ============================== */
#toastRoot { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #0f172a; color: #fff; padding: 12px 18px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  transform: translateX(120%); opacity: 0; transition: all 0.25s;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast.toast-success { background: #059669; }
.toast.toast-error { background: #dc2626; }
.toast.toast-warn { background: #d97706; }
.toast.toast-info { background: var(--primary-dark); }

/* ============================== EMPTY PAGE ============================== */
.empty-page { padding: 60px 20px; text-align: center; color: var(--text-muted); }

/* ============================== RESPONSIVE ============================== */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  :root { --sidebar-w: 100%; }
  .sidebar { position: relative; height: auto; max-height: none; }
  nav#navList { display: flex; overflow-x: auto; padding: 8px; }
  .nav-item { white-space: nowrap; padding: 8px 14px; border-left: none; border-bottom: 3px solid transparent; }
  .nav-item.active { border-left-color: transparent; border-bottom-color: var(--primary); }
  .user-info { padding: 10px 16px; }
  .main { margin-left: 0; padding: 16px; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .page-title { font-size: 18px; }
}
