/* ── Reset & Base ──────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --fg:    #1a1a1a;
  --fg2:   #6b6b6b;
  --bg:    #ffffff;
  --surf:  #f7f7f7;
  --line:  #e8e8e8;
  --accent: #d35322;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "SFMono-Regular", "Cascadia Code", "Fira Code", monospace;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  font-size: 14px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Login Page ────────────────────────────────── */
.page-login {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-wrap {
  width: 100%;
  max-width: 360px;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 48px;
}

.login-card {
  width: 100%;
}

.login-header {
  margin-bottom: 32px;
}

.login-header h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}

.login-header p {
  color: var(--fg2);
  font-size: 13px;
}

/* ── Form ──────────────────────────────────────── */
.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
  margin-bottom: 5px;
}

.field input {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(211, 83, 34, 0.08);
}

.field input::placeholder {
  color: #b0b0b0;
}

.error-msg {
  font-size: 13px;
  color: #c0392b;
  padding: 8px 10px;
  background: #fdf0ef;
  border-radius: var(--radius);
}

.btn-login {
  width: 100%;
  height: 36px;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
  color: #fff;
  background: var(--fg);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 4px;
}

.btn-login:hover {
  background: #333;
}

.btn-login:active {
  background: #000;
}

/* ── Dashboard Layout ──────────────────────────── */
.page-dash {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surf);
  border-right: 1px solid var(--line);
  padding: 20px 0;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 0 16px 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
  flex: 1;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--fg2);
  border-radius: var(--radius);
  text-decoration: none;
  transition: background 0.1s, color 0.1s;
}

.sidebar-nav a:hover {
  background: var(--line);
  color: var(--fg);
  text-decoration: none;
}

.sidebar-nav a.active {
  background: var(--line);
  color: var(--fg);
  font-weight: 500;
}

.sidebar-bottom {
  padding: 12px 8px 0;
  border-top: 1px solid var(--line);
  margin-top: auto;
}

.sidebar-bottom a {
  display: block;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--fg2);
  border-radius: var(--radius);
  text-decoration: none;
}

.sidebar-bottom a:hover {
  background: var(--line);
  color: var(--fg);
  text-decoration: none;
}

/* Sidebar mobile toggle */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 110;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: #1e2330;
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

@media (max-width: 860px) {
  .sidebar-toggle {
    display: inline-flex;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 220px;
    transform: translateX(-100%);
    transition: transform 200ms ease;
    z-index: 100;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
  }
  .sidebar-backdrop.open {
    display: block;
  }
  .main {
    padding: 20px;
    padding-top: 60px;
  }
}

/* ── Main Content ──────────────────────────────── */
.main {
  flex: 1;
  padding: 32px 40px;
  overflow-y: auto;
}

.main h2 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}

.main .subtitle {
  color: var(--fg2);
  font-size: 13px;
  margin-bottom: 24px;
}

/* ── Data Table ────────────────────────────────── */
.data-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data-table thead {
  background: var(--surf);
}

table.data-table th {
  text-align: left;
  padding: 8px 12px;
  font-weight: 500;
  color: var(--fg2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

table.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--fg);
}

table.data-table tbody tr:last-child td {
  border-bottom: none;
}

table.data-table tbody tr:hover {
  background: var(--surf);
}

.mono {
  font-family: var(--mono);
  font-size: 12px;
}

.table-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.table-controls select,
.table-controls input {
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

.table-controls select { width: 140px; }
.table-controls input  { width: 240px; }

.table-controls select:focus,
.table-controls input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(211, 83, 34, 0.08);
}

.tag-type {
  font-size: 12px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surf);
  color: var(--fg2);
  white-space: nowrap;
}

.payload-cell {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Table Controls ─────────────────────────────── */
/* Append everything below to the bottom of assets/styles.css */

.table-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.table-controls select,
.table-controls input {
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

.table-controls select { width: 140px; }
.table-controls input  { width: 240px; }

.table-controls select:focus,
.table-controls input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(211, 83, 34, 0.08);
}

/* ── Type Tags ─────────────────────────────────── */
.tag-type {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--surf);
  color: var(--fg2);
  white-space: nowrap;
}

.tag-static      { background: #e8f4f0; color: #1a6b52; }
.tag-performance { background: #fef3e2; color: #9a5c1b; }
.tag-activity    { background: #eef0fa; color: #4a50a3; }

/* ── Expandable Rows ───────────────────────────── */
.event-row {
  cursor: pointer;
  transition: background 0.1s;
}

.event-row:hover {
  background: var(--surf);
}

.expand-cell {
  text-align: center;
  width: 28px;
}

.expand-icon {
  display: inline-block;
  font-size: 14px;
  color: var(--fg2);
  transition: transform 0.15s;
}

.event-row.expanded .expand-icon {
  transform: rotate(90deg);
}

.page-cell {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-cell {
  font-size: 12px;
  color: var(--fg2);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  color: var(--fg2);
  padding: 24px 12px !important;
  text-align: center;
}

/* ── Detail Panel ──────────────────────────────── */
.detail-row {
  background: var(--surf);
}

.detail-cell {
  padding: 16px 20px !important;
  border-bottom: 1px solid var(--line) !important;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px 16px;
  margin-bottom: 12px;
}

.detail-kv {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.detail-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--fg2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-value {
  font-size: 13px;
  color: var(--fg);
  word-break: break-all;
}

/* ── Mini Table (activity events) ──────────────── */
.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-bottom: 12px;
}

.mini-table th {
  text-align: left;
  padding: 4px 8px;
  font-weight: 500;
  color: var(--fg2);
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.mini-table td {
  padding: 3px 8px;
  color: var(--fg);
  border-bottom: 1px solid var(--line);
}

.mini-table tbody tr:last-child td {
  border-bottom: none;
}

/* ── Raw Payload Toggle ────────────────────────── */
.raw-toggle {
  margin-top: 8px;
}

.raw-toggle summary {
  font-size: 12px;
  color: var(--fg2);
  cursor: pointer;
  padding: 4px 0;
}

.raw-toggle summary:hover {
  color: var(--fg);
}

.payload-pre {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  overflow-x: auto;
  max-height: 300px;
  margin-top: 6px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Detail Meta Footer ────────────────────────── */
.detail-meta {
  display: flex;
  gap: 20px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--fg2);
}

.detail-meta .mono {
  font-size: 11px;
}

/* ── Pagination ────────────────────────────────── */
.table-controls button {
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.table-controls button:hover:not(:disabled) {
  background: var(--surf);
}

.table-controls button:disabled {
  opacity: 0.4;
  cursor: default;
}

#page-index {
  font-size: 13px;
  color: var(--fg2);
  align-self: center;
  white-space: nowrap;
}

/* ── Charts Section ────────────────────────────── */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 24px;
}

.chart-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.chart-card h3 {
  font-size: 13px;
  font-weight: 500;
  color: var(--fg2);
  margin-bottom: 12px;
}

.chart-card canvas {
  width: 100% !important;
  max-height: 300px;
}

@media (max-width: 800px) {
  .chart-grid { grid-template-columns: 1fr; }
}

/* ── Login Footer ──────────────────────────────── */
.login-footer {
  font-size: 12px;
  color: #b0b0b0;
}

/* Page header with date filter */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.date-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.date-filter label {
  font-size: 12px;
  color: var(--fg2);
  margin-bottom: 0;
}

.date-filter input[type="date"] {
  height: 32px;
  padding: 0 8px;
  font-size: 13px;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  width: auto;
}

.date-filter input[type="date"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(211, 83, 34, 0.08);
}

.filter-btn {
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  color: #fff;
  background: var(--fg);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}

.filter-btn:hover { background: #333; }

.filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.filter-btn img {
  flex-shrink: 0;
  filter: brightness(0) invert(1);
  opacity: 0.7;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--fg2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  font-size: 26px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.02em;
}

.kpi-sub {
  font-size: 12px;
  font-weight: 500;
}

/* Analyst textarea */
.analyst-textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #ddd;
  font-size: 0.92rem;
  font-family: inherit;
  resize: vertical;
  margin-top: 8px;
}

/* Error tag */
.tag-error {
  background: #fdf0ef;
  color: #c0392b;
}

/* Admin page */
.admin-msg {
  font-size: 13px;
  padding: 8px 12px;
  background: var(--surf);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 16px;
  color: var(--fg);
}

.admin-add-form {
  margin-top: 24px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.admin-add-form h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}

.add-user-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.add-user-row input,
.add-user-row select {
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  width: auto;
}

.add-user-row input { width: 180px; }
.add-user-row select { width: 120px; }

.remove-btn {
  font-size: 12px;
  font-family: var(--font);
  color: #c0392b;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.remove-btn:hover {
  background: #fdf0ef;
}

/* Admin messages */
.msg-success {
  background: rgba(26, 138, 74, 0.1);
  color: #1a8a4a;
  border-left: 3px solid #1a8a4a;
}
.msg-error {
  background: rgba(192, 57, 43, 0.1);
  color: #c0392b;
  border-left: 3px solid #c0392b;
}

/* Role tag colors */
.tag-super_admin { background: rgba(163, 6, 7, 0.12); color: #a40607; }
.tag-admin { background: rgba(33, 46, 80, 0.12); color: #212e50; }
.tag-analyst { background: rgba(43, 73, 73, 0.12); color: #2b4949; }
.tag-viewer { background: rgba(107, 107, 107, 0.12); color: #6b6b6b; }

/* Add user form */
.add-user-form { margin-top: 8px; }
.add-user-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: stretch;
}
.add-user-row input,
.add-user-row select {
  min-width: 0;
  flex: 1;
  min-height: 38px;
}

/* Edit user modal */
#edit-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
#edit-overlay.open,
#edit-overlay[style*="flex"] {
  display: flex;
}
#edit-overlay .modal {
  background: var(--bg, #fff);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 20px 46px rgba(0,0,0,0.18);
  width: min(460px, 100%);
}
#edit-overlay .modal label {
  display: block;
  font-size: 0.88rem;
  color: #666;
  margin-bottom: 4px;
}
#edit-overlay .modal input,
#edit-overlay .modal select {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #ddd;
  font-size: 0.92rem;
  margin-bottom: 4px;
}

/* Sidebar nav updates for 5 items */
@media (max-width: 800px) {
  .page-header { flex-direction: column; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}