/* GuardWatch Pro — App Styles */

:root {
  --purple: #8B5CF6;
  --purple-light: #a78bfa;
  --purple-dark: #7c3aed;
  --cyan: #06b6d4;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --pink: #ec4899;
  --blue: #3b82f6;
  --grey: #6b7280;
  --bg: #f8f7ff;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e5e0ff;
  --shadow: 0 4px 24px rgba(139, 92, 246, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

/* ── Header ── */
.app-header {
  background: var(--surface);
  border-bottom: 2px solid var(--purple);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
.app-header h1 { font-size: 20px; font-weight: 800; color: var(--purple); }
.app-header .role-badge { background: var(--purple); color: #fff; padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; }

/* ── Tabs ── */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; background: var(--surface); padding: 8px; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.tab-btn { padding: 10px 18px; border: 2px solid transparent; background: var(--purple); border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; font-weight: 600; color: #fff; white-space: nowrap; transition: all 0.15s; }
.tab-btn:hover { background: #7c3aed; }
.tab-btn.active { background: var(--purple); border-color: #000; box-shadow: 0 0 0 1px #000; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Cards ── */
.card { background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-title { font-size: 14px; font-weight: 700; color: var(--purple); text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }

/* ── Stats Grid ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--surface); border-radius: var(--radius); padding: 18px; text-align: center; border: 1px solid var(--border); }
.stat-num { font-size: 28px; font-weight: 800; }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; margin-top: 4px; letter-spacing: 0.5px; }
.stat.green .stat-num { color: var(--green); }
.stat.red .stat-num { color: var(--red); }
.stat.amber .stat-num { color: var(--amber); }
.stat.purple .stat-num { color: var(--purple); }

/* ── Guard Grid (Overview) ── */
.guard-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.guard-card { background: var(--surface); border-radius: var(--radius); padding: 16px; border: 2px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.guard-card.active { border-color: var(--green); }
.guard-card.break { border-color: var(--amber); }
.guard-card.panic { border-color: var(--red); animation: panicPulse 1s infinite; }
@keyframes panicPulse { 0%,100%{box-shadow:0 0 0 0 rgba(239,68,68,0.5)} 50%{box-shadow:0 0 0 8px rgba(239,68,68,0)} }
.guard-avatar { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 800; color: #fff; }
.guard-name { font-size: 15px; font-weight: 700; }
.guard-status { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.status-active { color: var(--green); }
.status-break { color: var(--amber); }
.status-off { color: var(--grey); }
.status-panic { color: var(--red); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { background: var(--bg); padding: 10px 12px; text-align: left; font-weight: 700; border-bottom: 2px solid var(--border); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tr:hover { background: #faf9ff; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot-green { background: var(--green); }
.dot-amber { background: var(--amber); }
.dot-red { background: var(--red); }
.dot-grey { background: var(--grey); }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px; border: none; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.2s; text-decoration: none; }
.btn-primary { background: var(--purple); color: #fff; }
.btn-primary:hover { background: var(--purple-dark); }
.btn-secondary { background: var(--bg); color: var(--purple); border: 1px solid var(--border); }
.btn-secondary:hover { background: #ede9ff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-warning { background: var(--amber); color: #fff; }
.btn-warning:hover { background: #d97706; }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { display: block; width: 100%; text-align: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Form Elements ── */
.form-group { margin-bottom: 16px; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
input, select, textarea { width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; background: var(--surface); color: var(--text); transition: border-color 0.2s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--purple); box-shadow: 0 0 0 3px rgba(139,92,246,0.1); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

/* ── Login Screen (field.html) ── */
.login-screen { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(135deg, #1a1a2e 0%, #2d1b69 100%); }
.login-box { background: var(--surface); border-radius: var(--radius); padding: 40px; width: 100%; max-width: 400px; box-shadow: 0 24px 64px rgba(0,0,0,0.3); }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo h1 { font-size: 28px; font-weight: 900; color: var(--purple); margin-bottom: 4px; }
.login-logo p { font-size: 13px; color: var(--text-muted); }
.login-logo .logo-icon { font-size: 48px; margin-bottom: 8px; }

/* ── Guard Station (field.html) ── */
.station-header { background: var(--purple); color: #fff; padding: 20px; text-align: center; }
.station-header h2 { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.station-header .guard-name-display { font-size: 14px; opacity: 0.9; }

/* ── Action Buttons ── */
.action-grid { display: grid; gap: 12px; padding: 20px; }
.awake-btn { background: var(--green); color: #fff; padding: 20px; border-radius: var(--radius); font-size: 18px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; border: none; cursor: pointer; transition: all 0.2s; box-shadow: 0 4px 20px rgba(34,197,94,0.4); }
.awake-btn:hover { background: #16a34a; transform: translateY(-2px); box-shadow: 0 6px 24px rgba(34,197,94,0.5); }
.awake-btn:disabled { background: var(--grey); box-shadow: none; transform: none; cursor: not-allowed; }

.panic-btn {
  background: var(--red);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 32px rgba(239,68,68,0.6);
  animation: panicGlow 1.5s ease-in-out infinite;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 4px;
}
@keyframes panicGlow {
  0%,100%{ box-shadow: 0 8px 32px rgba(239,68,68,0.6); }
  50%{ box-shadow: 0 8px 60px rgba(239,68,68,1.0), 0 0 80px rgba(239,68,68,0.4); }
}
.panic-btn:hover { background: #dc2626; }

.break-btn { background: var(--amber); color: #fff; padding: 16px; border-radius: var(--radius); font-size: 14px; font-weight: 700; border: none; cursor: pointer; }
.break-btn:hover { background: #d97706; }
.break-btn.end { background: var(--blue); }

.incident-btn { background: var(--grey); color: #fff; padding: 16px; border-radius: var(--radius); font-size: 14px; font-weight: 700; border: none; cursor: pointer; }
.incident-btn:hover { background: #4b5563; }

.sign-out-btn { background: transparent; border: 2px solid rgba(255,255,255,0.3); color: #fff; padding: 16px; border-radius: var(--radius); font-size: 14px; font-weight: 600; cursor: pointer; }
.sign-out-btn:hover { border-color: rgba(255,255,255,0.7); background: rgba(255,255,255,0.1); }

.action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Spot Check Alert ── */
.spot-check-alert { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(239,68,68,0.95); z-index: 1000; align-items: center; justify-content: center; flex-direction: column; text-align: center; color: #fff; padding: 40px; }
.spot-check-alert.visible { display: flex; animation: flashAlert 0.5s infinite; }
@keyframes flashAlert { 0%,100%{background:rgba(239,68,68,0.95)} 50%{background:rgba(220,38,38,0.95)} }
.spot-check-alert h2 { font-size: 32px; font-weight: 900; margin-bottom: 16px; text-transform: uppercase; letter-spacing: 3px; }
.spot-check-alert p { font-size: 18px; margin-bottom: 24px; }
.spot-check-timer { font-size: 64px; font-weight: 900; margin-bottom: 24px; }

/* ── Loading / Spinner ── */
.spinner { width: 40px; height: 40px; border: 4px solid var(--border); border-top-color: var(--purple); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 40px auto; }
@keyframes spin { to{transform:rotate(360deg)} }
.loading-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(248,247,255,0.9); z-index: 999; display: flex; align-items: center; justify-content: center; flex-direction: column; }
.loading-overlay.hidden { display: none; }

/* ── Toast / Notification ── */
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--text); color: #fff; padding: 14px 20px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,0.2); transform: translateY(100px); opacity: 0; transition: all 0.3s; z-index: 2000; }
.toast.visible { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.warning { background: var(--amber); }

/* ── Modal ── */
.modal-backdrop { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(26,26,46,0.7); z-index: 1000; display: none; align-items: center; justify-content: center; padding: 24px; }
.modal-backdrop.visible { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 28px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-title { font-size: 18px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-footer { display: flex; gap: 12px; justify-content: flex-end; margin-top: 20px; }

/* ── Calendar ── */
.calendar { font-size: 12px; }
.calendar-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.calendar-nav h3 { font-size: 16px; font-weight: 700; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.calendar-day-header { text-align: center; font-size: 10px; font-weight: 700; color: var(--text-muted); padding: 4px; text-transform: uppercase; }
.calendar-day { aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 4px; cursor: pointer; font-size: 12px; padding: 2px; border: 1px solid transparent; }
.calendar-day:hover { background: var(--bg); }
.calendar-day.today { border-color: var(--purple); font-weight: 700; }
.calendar-day.has-shifts { background: rgba(139,92,246,0.1); }
.calendar-day .day-num { font-weight: 600; }
.calendar-day .shift-dot { width: 6px; height: 6px; border-radius: 50%; margin-top: 1px; }

/* ── Master Calendar ── */
.master-cal { font-size: 12px; }
.master-cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.master-cal-title { font-size: 20px; font-weight: 800; color: var(--purple); }
.master-cal-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.mc-legend-item { display: flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; color: var(--text-muted); }
.master-cal-months { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 900px) { .master-cal-months { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 500px) { .master-cal-months { grid-template-columns: repeat(1, 1fr); } }
.master-cal-month { background: var(--surface); border-radius: var(--radius); padding: 10px; border: 1px solid var(--border); }
.master-cal-month-name { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--purple); margin-bottom: 6px; text-align: center; }
.master-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
.mc-day-header { text-align: center; font-size: 9px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; padding: 2px 0; }
.mc-day { aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding: 2px; border-radius: 3px; cursor: pointer; border: 1px solid transparent; min-height: 24px; gap: 1px; }
.mc-day:hover { background: var(--bg); }
.mc-day.mc-empty { cursor: default; }
.mc-day.mc-empty:hover { background: transparent; }
.mc-day.mc-today { border-color: var(--purple); }
.mc-day.mc-has-shifts { background: rgba(139,92,246,0.08); }
.mc-day-num { font-size: 10px; font-weight: 600; line-height: 1; }
.mc-dot { width: 6px; height: 6px; border-radius: 50%; display: block; }
.mc-more { font-size: 8px; color: #fff; text-align: center; line-height: 6px; font-weight: 700; }
.mc-today .mc-day-num { color: var(--purple); font-weight: 800; }

/* ── Incident Badge ── */
.incident-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.incident-badge.panic { background: rgba(239,68,68,0.15); color: var(--red); }
.incident-badge.suspicious { background: rgba(245,158,11,0.15); color: var(--amber); }
.incident-badge.medical { background: rgba(6,182,212,0.15); color: var(--cyan); }
.incident-badge.property { background: rgba(59,130,246,0.15); color: var(--blue); }
.incident-badge.other { background: rgba(107,114,128,0.15); color: var(--grey); }

/* ── Compliance Ring ── */
.compliance-ring { position: relative; width: 60px; height: 60px; }
.compliance-ring svg { transform: rotate(-90deg); width: 60px; height: 60px; }
.compliance-ring circle { fill: none; stroke-width: 4; }
.compliance-ring .bg { stroke: var(--border); }
.compliance-ring .fg { stroke-linecap: round; }
.compliance-ring .value { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 12px; font-weight: 800; }

/* ── Empty State ── */
.empty-state { text-align: center; padding: 40px; color: var(--text-muted); }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { font-size: 14px; }

/* ── Footer nav (field) ── */
.station-footer { display: flex; gap: 4px; background: var(--surface); padding: 8px; border-top: 1px solid var(--border); position: fixed; bottom: 0; left: 0; right: 0; }
.nav-btn { flex: 1; padding: 10px; border: none; background: var(--bg); border-radius: var(--radius-sm); font-size: 11px; font-weight: 600; text-align: center; cursor: pointer; color: var(--text-muted); }
.nav-btn.active { background: var(--purple); color: #fff; }
.nav-btn .icon { font-size: 18px; display: block; margin-bottom: 2px; }

/* ── Cartoon Guard Character (Briefing Tab) ── */
.briefing-ai-section {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 24px;
}

.cartoon-guard-wrap {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Guard character */
.cartoon-guard {
  position: relative;
  width: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Head */
.guard-head {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #fcd5a7;
  border: 2px solid #e8b87a;
  position: relative;
  z-index: 2;
}

/* Face — eyes */
.guard-head::before,
.guard-head::after {
  content: '';
  position: absolute;
  top: 18px;
  width: 7px;
  height: 7px;
  background: #2d1b69;
  border-radius: 50%;
}
.guard-head::before { left: 13px; }
.guard-head::after { right: 13px; }

/* Smile */
.guard-smile {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 18px;
  height: 9px;
  border-bottom: 2.5px solid #c96a3a;
  border-left: 2.5px solid #c96a3a;
  border-right: 2.5px solid #c96a3a;
  border-radius: 0 0 18px 18px;
  background: transparent;
}

/* Security cap */
.guard-cap {
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 22px;
  background: #1e3a5f;
  border-radius: 30px 30px 0 0;
  z-index: 3;
}
.guard-cap::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: -4px;
  width: 68px;
  height: 6px;
  background: #1e3a5f;
  border-radius: 2px;
}
/* Cap badge/logo */
.guard-cap::before {
  content: '★';
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  color: #f59e0b;
  font-size: 10px;
  z-index: 4;
}

/* Body / uniform */
.guard-body {
  width: 56px;
  height: 48px;
  background: #1e5a3a;
  border-radius: 10px 10px 14px 14px;
  margin-top: -6px;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

/* Badge on chest */
.guard-badge {
  width: 16px;
  height: 20px;
  background: #f59e0b;
  border-radius: 3px;
  border: 1.5px solid #d97706;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 6px;
}
.guard-badge::before {
  content: '🛡';
  font-size: 9px;
  line-height: 1;
}

/* Arms */
.guard-arm-left,
.guard-arm-right {
  position: absolute;
  top: 4px;
  width: 14px;
  height: 28px;
  background: #1e5a3a;
  border-radius: 8px;
  z-index: 0;
}
.guard-arm-left { left: -10px; }
.guard-arm-right { right: -10px; }

/* Legs */
.guard-legs {
  display: flex;
  gap: 6px;
  margin-top: -2px;
}
.guard-leg {
  width: 18px;
  height: 22px;
  background: #1e3a5f;
  border-radius: 0 0 6px 6px;
}

/* Feet */
.guard-feet {
  display: flex;
  gap: 2px;
  margin-top: -2px;
}
.guard-foot {
  width: 22px;
  height: 8px;
  background: #111;
  border-radius: 4px 4px 0 0;
}

/* Speech bubble */
.speech-bubble {
  position: relative;
  background: #fff;
  border: 2px solid #1e3a5f;
  border-radius: 16px;
  padding: 14px 16px;
  max-width: 300px;
  min-width: 220px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  margin-left: 16px;
  margin-bottom: 8px;
}

/* Bubble tail — points down-left toward guard */
.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -14px;
  left: 28px;
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 14px solid #1e3a5f;
}
.speech-bubble::before {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 30px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 11px solid #fff;
  z-index: 1;
}

.speech-bubble-header {
  font-size: 10px;
  font-weight: 700;
  color: var(--purple);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.speech-bubble-header::before {
  content: '🤖';
  font-size: 12px;
}

.speech-bubble-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.5;
}

.speech-bubble-status {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .guard-grid { grid-template-columns: 1fr; }
  .action-row { grid-template-columns: 1fr; }
  .app-header { padding: 12px 16px; }
  .app-header h1 { font-size: 16px; }
  .login-box { padding: 24px; }
  .station-footer { padding-bottom: env(safe-area-inset-bottom, 8px); }
}

/* ── Print ── */
@media print { .no-print { display: none !important; } }