@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@500;600&display=swap');

/* ==========================================================================
   Tokens
   ========================================================================== */
:root {
  /* Surfaces */
  --bg: #f4f8f7;
  --surface: #ffffff;
  --surface-alt: #eef5f3;
  --border: #dbe6e3;

  /* Text */
  --text: #142523;
  --text-muted: #5c716e;

  /* Brand / primary action — deep clinical teal */
  --primary: #0d6e64;
  --primary-dark: #0a544c;
  --primary-tint: #e2f2ef;

  /* Severity scale — reused for role badges & flash messages,
     modeled loosely on a vitals-monitor read: critical / caution / info / normal */
  --critical: #b8412b;
  --critical-bg: #fbeae5;
  --warning: #a8721a;
  --warning-bg: #fbf0dc;
  --info: #1d5a96;
  --info-bg: #e6eef8;
  --normal: #2f7a4d;
  --normal-bg: #e9f5ee;

  /* Type */
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --radius: 8px;
  --shadow: 0 1px 2px rgba(20, 37, 35, 0.05), 0 4px 14px rgba(20, 37, 35, 0.05);
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden; /* hard safety net: sideways scroll cannot happen site-wide */
}

body {
  margin: 0;
  max-width: 100%;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word; /* long emails/names/IDs wrap instead of forcing width;
                                 'break-word' (unlike 'anywhere') doesn't affect how
                                 browsers auto-size table columns, so desktop tables
                                 still size to fit their content on one line */
}

a {
  color: var(--primary);
  text-decoration: none;
}

h1, h2, h3 {
  font-family: var(--font-display);
  letter-spacing: -0.01em;
}

/* ==========================================================================
   Signature motif: a heartbeat pulse-line, used once, quietly, under the topbar
   ========================================================================== */
.topbar {
  background: var(--surface);
  padding: 16px 20px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar::after {
  content: "";
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 14px;
  margin-top: 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='14' viewBox='0 0 140 14'%3E%3Cpath d='M0 7 H50 L57 1 L64 13 L71 4 L78 7 H140' fill='none' stroke='%230d6e64' stroke-width='1.4' stroke-opacity='0.35' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  background-size: 140px 14px;
}

.topbar {
  margin-bottom: 14px;
}

.topbar .brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  padding-bottom: 16px;
}

.topbar .brand span {
  color: var(--primary);
}

.topbar > * {
  padding-bottom: 16px;
}

/* ==========================================================================
   Layout
   ========================================================================== */
.container {
  max-width: 440px;
  margin: 48px auto;
  padding: 0 16px;
}

.container-wide {
  max-width: 1320px;
  margin: 8px auto 24px;
  padding: 0 16px 60px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px 28px;
  animation: rise 0.35s ease-out both;
}

.card + .card {
  margin-top: 20px;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .card { animation: none; }
}

.card-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0 0 4px;
}

.card-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0 0 22px;
}

/* ==========================================================================
   Forms
   ========================================================================== */
.form-group {
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 16px; /* keeps iOS Safari from auto-zooming on focus */
  font-family: var(--font-body);
  background: #fbfdfc;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
}

.search-bar {
  margin-bottom: 16px;
  max-width: 340px;
}

.search-results-count {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: -8px 0 14px;
}

.no-results {
  display: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 16px 0;
  text-align: center;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-tint);
  background: #fff;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 44px;
  padding: 11px 16px;
  border: none;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: background 0.15s;
}

.btn:hover {
  background: var(--primary-dark);
}

.btn:focus-visible,
a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
}

.btn-secondary:hover {
  background: #e2ede9;
}

.btn-sm {
  width: auto;
  min-height: 38px;
  padding: 8px 14px;
  font-size: 0.85rem;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-outline:hover {
  background: var(--surface-alt);
}

.form-footer {
  text-align: center;
  margin-top: 18px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Flash messages — same severity scale as role badges
   ========================================================================== */
.flash {
  padding: 12px 14px;
  border-radius: 6px;
  font-size: 0.88rem;
  margin-bottom: 14px;
  border: 1px solid transparent;
}

.flash-success {
  background: var(--normal-bg);
  color: var(--normal);
  border-color: #c8e6d3;
}

.flash-error {
  background: var(--critical-bg);
  color: var(--critical);
  border-color: #f0cec4;
}

/* ==========================================================================
   Dashboard
   ========================================================================== */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.stat .label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.stat .value {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 600;
  margin-top: 6px;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  font-family: var(--font-mono);
}

/* Severity mapping: super admin = critical, admin = caution,
   floor manager = info, employee = normal/neutral baseline */
.badge-super_admin { background: var(--critical-bg); color: var(--critical); }
.badge-admin        { background: var(--warning-bg); color: var(--warning); }
.badge-floor_manager{ background: var(--info-bg); color: var(--info); }
.badge-employee      { background: var(--surface-alt); color: var(--text-muted); }

/* Attendance status — a different axis of meaning from role, so it gets its
   own pair of colors rather than reusing the role badges above. */
.badge-present { background: var(--normal-bg); color: var(--normal); }
.badge-absent  { background: var(--critical-bg); color: var(--critical); }

.profile-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--primary-tint);
  border: 2px solid var(--surface);
  outline: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-align: center;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap; /* desktop: cells size to fit content on one line;
                           if a table genuinely can't fit, .table-wrap's own
                           overflow-x:auto scrolls just the table, not the page */
}

td:first-child, th:first-child {
  font-family: var(--font-mono);
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tbody tr:hover {
  background: var(--surface-alt);
}

.table-wrap {
  overflow-x: auto;
}


.section-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 14px;
}

/* ==========================================================================
   Camera
   ========================================================================== */
#camera-wrap {
  display: none;
  margin-top: 14px;
}

#camera-wrap.active {
  display: block;
}

video, canvas {
  width: 100%;
  max-width: 360px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #000;
}

.camera-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.camera-actions .btn {
  width: auto;
  flex: 1 1 100px;
  min-width: 0;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 480px) {
  .container {
    margin: 20px auto;
  }
  .card {
    padding: 22px 18px;
  }
  .topbar {
    padding: 14px 14px 0;
  }
}

/* On phones, tables with several columns (Staff Directory, Attendance,
   History) stop being tables and become a stack of labeled cards —
   a lot easier to read and tap than a cramped, horizontally-scrolled grid. */
@media (max-width: 700px) {
  .table-wrap table,
  .table-wrap thead,
  .table-wrap tbody,
  .table-wrap th,
  .table-wrap tr {
    display: block;
  }

  .table-wrap thead {
    /* Hidden but still present for screen readers */
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .table-wrap tbody tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 14px;
    margin-bottom: 12px;
  }

  .table-wrap tbody tr:hover {
    background: var(--surface);
  }

  .table-wrap td {
    display: block;
    border-bottom: 1px solid var(--border);
    padding: 10px 0;
    font-family: var(--font-body);
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .table-wrap td:last-child {
    border-bottom: none;
  }

  .table-wrap td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
  }

  .table-wrap td form {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    max-width: 100%;
  }

  .table-wrap td select {
    width: auto;
    max-width: 100%;
    flex: 1 1 auto;
    min-width: 0;
  }

  .table-wrap td .btn,
  .table-wrap td button {
    max-width: 100%;
    flex-shrink: 0;
  }
}

/* Desktop only (mobile switches the same table to stacked cards above, and
   should stay untouched). Used on tables where several cells hold an inline
   <select>+<button> form (Staff Directory) — tightens things up so more
   columns fit before the table needs to scroll sideways. */
@media (min-width: 701px) {
  .table-compact th,
  .table-compact td {
    padding: 8px 6px;
  }

  .table-compact select {
    width: auto;
    max-width: 108px;
    padding: 4px 6px;
    font-size: 0.82rem;
  }

  .table-compact td form {
    gap: 4px;
  }

  .table-compact .btn-sm {
    padding: 4px 10px;
    font-size: 0.78rem;
  }

  .table-compact .actions-stack {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
  }
}

/* ==========================================================================
   Bottom navigation (mobile only) — a persistent, thumb-reachable way to
   move between sections, the way native Android apps do. Hidden on
   desktop, where the topbar and in-page links already cover navigation.
   ========================================================================== */
.bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  body.has-bottom-nav {
    /* keeps page content from being hidden behind the fixed nav bar */
    padding-bottom: calc(70px + env(safe-area-inset-bottom));
  }

  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around;
    align-items: stretch;
  }

  .bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 4px;
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.66rem;
    font-weight: 600;
    text-decoration: none;
    min-height: 48px; /* comfortable tap target */
  }

  .bottom-nav a svg {
    width: 22px;
    height: 22px;
  }

  .bottom-nav a.active {
    color: var(--primary);
    background: var(--primary-tint);
  }
}
