/* AlphaManager — owner-facing admin dashboard
   Vanilla CSS, legacy-palette, no framework. */

:root {
  --bg: #f7fafc;
  --surface: #ffffff;
  --text: #2d3748;
  --text-muted: #718096;
  --text-subtle: #a0aec0;
  --border: #e2e8f0;
  --border-strong: #cbd5e0;
  --accent: #4299e1;
  --accent-dark: #3182ce;
  --success: #48bb78;
  --success-bg: #f0fff4;
  --danger: #f56565;
  --danger-bg: #fff5f5;
  --warning: #ed8936;
  --info: #4299e1;
  --info-bg: #ebf8ff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-width: 232px;
  --gap: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

body { min-height: 100vh; }

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

h1, h2, h3 { margin: 0 0 8px; color: var(--text); }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 20px; font-weight: 600; }

p { margin: 0 0 12px; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.strong { font-weight: 600; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.meta { color: var(--text-muted); font-size: 12px; }
.meta-error { color: var(--danger); }
.inline { display: inline; }

/* Layout ------------------------------------------------------------------ */

body:not(.no-chrome) { display: flex; align-items: stretch; }

.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 20px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  background: var(--accent);
  color: white;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 14px;
}
.brand-mark.large {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  font-size: 22px;
}

.brand-name { font-weight: 700; font-size: 17px; }

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 10px;
  flex: 1;
}

.nav-link {
  display: block;
  padding: 10px 14px;
  color: var(--text);
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.nav-link:hover { background: var(--bg); text-decoration: none; }
.nav-link.active { background: var(--info-bg); color: var(--accent-dark); font-weight: 600; }

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.who-name { font-weight: 600; }
.who-role { color: var(--text-muted); font-size: 12px; }

.main {
  flex: 1;
  padding: 28px 36px 48px;
  max-width: calc(100% - var(--sidebar-width));
}

.main-bare {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-header h1 { margin: 0; }
.page-header p { margin: 4px 0 0; }

/* Flashes ----------------------------------------------------------------- */

.flashes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }

.flash {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 14px;
}
.flash-success { border-color: var(--success); background: var(--success-bg); color: #276749; }
.flash-error { border-color: var(--danger); background: var(--danger-bg); color: #9b2c2c; }
.flash-info { border-color: var(--accent); background: var(--info-bg); color: var(--accent-dark); }

/* Hero cards -------------------------------------------------------------- */

.hero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.hero-card-success { border-left: 4px solid var(--success); }
.hero-card-info    { border-left: 4px solid var(--info); }
.hero-card-neutral { border-left: 4px solid var(--text-subtle); }

.hero-number { font-size: 32px; font-weight: 800; letter-spacing: -0.02em; }
.hero-label  { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* Lists panels ------------------------------------------------------------ */

.lists-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}

.list-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.list-panel > summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
}
.list-panel > summary::-webkit-details-marker { display: none; }
.list-panel .count {
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
}

.name-list { list-style: none; padding: 6px 0 4px; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.name-list.columns-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 16px;
}

.name-list li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--border);
}
.name-list li:last-child { border-bottom: none; }

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block;
}
.dot-success { background: var(--success); }
.dot-info    { background: var(--info); }
.dot-neutral { background: var(--text-subtle); }
.name { color: var(--text); }
.empty { color: var(--text-muted); font-style: italic; padding: 8px 0; }

/* Tables ------------------------------------------------------------------ */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  box-shadow: var(--shadow-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table thead th {
  background: #fafcff;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.data-table tbody tr:hover { background: #f9fbfd; }
.data-table tfoot td { background: #f6f9fc; font-weight: 600; border-top: 2px solid var(--border-strong); }
.data-table.compact th, .data-table.compact td { padding: 8px 10px; }

.num { text-align: right; }
.actions-col { text-align: right; white-space: nowrap; }
.actions-col .btn + .btn, .actions-col form + form, .actions-col form + .btn, .actions-col .btn + form { margin-left: 6px; }
.row-inactive td { opacity: 0.6; }

/* Pills ------------------------------------------------------------------- */

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg);
  color: var(--text-muted);
}
.pill-success { background: var(--success-bg); color: #276749; }
.pill-danger  { background: var(--danger-bg);  color: #9b2c2c; }
.pill-muted   { background: var(--bg);         color: var(--text-muted); }
.pill-worker  { background: #edf2f7; color: #2d3748; }
.pill-manager { background: #fefcbf; color: #744210; }
.pill-admin   { background: #fed7e2; color: #702459; }

/* Buttons ----------------------------------------------------------------- */

.btn {
  display: inline-block;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  line-height: 1;
}
.btn:hover { background: #f7fafc; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: white; font-weight: 600; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-danger { background: var(--danger-bg); border-color: var(--danger); color: #9b2c2c; }
.btn-danger:hover { background: #fed7d7; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-small { padding: 5px 10px; font-size: 12px; }
.btn-wide { width: 100%; padding: 12px; font-size: 15px; }

/* Forms ------------------------------------------------------------------- */

.stack { display: flex; flex-direction: column; gap: 12px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field .label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.field input,
.field select,
.field textarea {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font: inherit;
  background: white;
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.radio-row {
  display: flex;
  gap: 18px;
  padding: 6px 0;
  font-size: 15px;
}

/* Login ------------------------------------------------------------------- */

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 36px;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 380px;
}
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 22px;
  text-align: center;
}
.login-brand h1 { margin: 14px 0 4px; font-size: 22px; }

/* Dialog ------------------------------------------------------------------ */

.dialog {
  border: none;
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 24px 48px rgba(0,0,0,0.18);
  max-width: 440px;
  width: 90vw;
  background: var(--surface);
  color: var(--text);
}
.dialog::backdrop { background: rgba(26, 32, 44, 0.55); }

.dialog h2 { margin-bottom: 8px; }

.dialog-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 14px;
}

/* Payroll grid ------------------------------------------------------------ */

.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.week-controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.payroll-grid .day-label {
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
}
.sticky-col {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 1;
  border-right: 1px solid var(--border);
  min-width: 200px;
}
.data-table thead .sticky-col { background: #fafcff; }
.data-table tfoot .sticky-col { background: #f6f9fc; }

.cell-day { padding: 4px; }
.cell-button {
  width: 100%;
  padding: 8px 4px;
  border: 1px dashed transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: var(--text);
  text-align: center;
}
.cell-button:hover { border-color: var(--accent); background: var(--info-bg); }
.cell-filled { background: var(--success-bg); font-weight: 600; }
.cell-empty  { color: var(--text-subtle); }
.cell-static { display: inline-block; padding: 8px 0; }

/* Locations --------------------------------------------------------------- */

.locations-layout {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 16px;
}
@media (max-width: 900px) {
  .locations-layout { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; min-height: unset; width: 100%; }
  body:not(.no-chrome) { flex-direction: column; }
  .main { max-width: 100%; padding: 20px; }
}

/* ================================================================
   AI Features — Payroll Review + Chat Widget
   ================================================================ */

/* AI Review Button */
.btn-ai {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff; font-weight: 600; font-size: 14px;
  border: none; cursor: pointer; transition: all 0.2s;
}
.btn-ai:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(102,126,234,0.4); }
.btn-ai:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* AI Review Panel */
.ai-panel {
  margin: 16px 0; border-radius: 12px; overflow: hidden;
  border: 1px solid #e0d4f5; background: #faf8ff;
  box-shadow: 0 2px 8px rgba(102,126,234,0.1);
}
.ai-panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff; font-weight: 600; font-size: 14px;
}
.ai-panel-body { padding: 16px; line-height: 1.6; font-size: 14px; }
.ai-panel-body h3 { margin: 12px 0 6px; font-size: 15px; }
.ai-panel-body h4 { margin: 10px 0 4px; font-size: 14px; }
.ai-panel-body ul { margin: 4px 0 8px 16px; }
.ai-panel-body li { margin: 2px 0; }
.ai-result { white-space: pre-wrap; }
.ai-error { color: #c0392b; font-weight: 500; }

/* Loading spinner */
.ai-loading { display: flex; align-items: center; gap: 10px; color: #666; }
.spinner {
  width: 20px; height: 20px; border: 3px solid #e0d4f5;
  border-top-color: #667eea; border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner-sm {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid #e0d4f5; border-top-color: #667eea;
  border-radius: 50%; animation: spin 0.8s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Close button */
.btn-close {
  background: none; border: none; color: #fff; font-size: 18px;
  cursor: pointer; padding: 0 4px; opacity: 0.8;
}
.btn-close:hover { opacity: 1; }

/* ================================================================
   AI Chat Widget — floating bottom-right
   ================================================================ */
.ai-chat-widget { position: fixed; bottom: 24px; right: 24px; z-index: 1000; }

.ai-chat-fab {
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none; font-size: 24px; cursor: pointer;
  box-shadow: 0 4px 16px rgba(102,126,234,0.4);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
.ai-chat-fab:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(102,126,234,0.5); }

.ai-chat-panel {
  display: none; flex-direction: column;
  width: 400px; height: 520px; border-radius: 16px;
  background: #fff; box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  overflow: hidden;
}

.ai-chat-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff; font-weight: 600; font-size: 14px;
}

.ai-chat-messages {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}

.ai-msg {
  padding: 10px 14px; border-radius: 12px;
  font-size: 13px; line-height: 1.5; max-width: 90%;
}
.ai-msg ul { margin: 4px 0 0 16px; padding: 0; }
.ai-msg li { margin: 2px 0; }

.ai-msg-assistant {
  background: #f0ecff; color: #333; align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.ai-msg-user {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff; align-self: flex-end; border-bottom-right-radius: 4px;
}
.ai-msg-error { background: #ffeaea; color: #c0392b; }

.ai-chat-input {
  display: flex; gap: 8px; padding: 12px;
  border-top: 1px solid #eee; background: #fafafa;
}
.ai-chat-input input {
  flex: 1; padding: 8px 12px; border: 1px solid #ddd;
  border-radius: 8px; font-size: 13px; outline: none;
}
.ai-chat-input input:focus { border-color: #667eea; }
.btn-sm { padding: 6px 14px; font-size: 13px; }

@media (max-width: 600px) {
  .ai-chat-panel { width: calc(100vw - 32px); height: 60vh; right: 0; bottom: 0; border-radius: 16px 16px 0 0; }
}
