@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:wght@400;700&display=swap');

:root {
  --bg: #f5f3ee;
  --panel: #ffffff;
  --ink: #23241f;
  --muted: #6b6d63;
  --accent: #2e6b4f;
  --accent-ink: #ffffff;
  --danger: #a4342a;
  --border: #ddd8cc;
  --radius: 14px;
  --header-bg: #1c203b;
  --header-ink: #e8e5d2;
  --shadow: 0 4px 16px rgba(20, 20, 10, 0.08);
  --header-h: 56px;
  --nav-h: 62px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: 'Atkinson Hyperlegible', Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.4;
  overscroll-behavior-y: none;
}

a { color: var(--accent); }

.page-center {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px calc(24px + var(--safe-bottom));
  padding-top: calc(24px + var(--safe-top));
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}

.card h1 {
  margin-top: 0;
  font-size: 1.4rem;
}

label {
  display: block;
  font-weight: 700;
  margin: 14px 0 4px;
  font-size: 0.9rem;
}

input, select, button, textarea {
  font-family: inherit;
  font-size: 16px;
}

input[type=text], input[type=email], input[type=password], input[type=time], input[type=date], input[type=number], select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}

input[type=range] { width: 100%; }

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-weight: 700;
  font-size: 0.95rem;
  transition: transform 0.1s ease, opacity 0.1s ease;
}

button:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  width: 100%;
  margin-top: 18px;
}

.btn-secondary {
  background: #eee;
  color: var(--ink);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-small {
  padding: 8px 12px;
  font-size: 0.85rem;
}

a.btn-primary, a.btn-secondary, a.btn-danger {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-weight: 700;
  font-size: 0.95rem;
  display: inline-block;
  text-align: center;
  text-decoration: none;
}

.status-msg {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  display: none;
}

.status-msg.show { display: block; }
.status-msg.success { background: #e2f2e8; color: #1c5c3e; }
.status-msg.error { background: #fbe6e3; color: var(--danger); }

.muted { color: var(--muted); font-size: 0.85rem; }

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0;
  color: var(--muted);
  font-size: 0.8rem;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e2e2e2;
}

.google-signin-btn { display: flex; justify-content: center; }

/* ===== App shell ===== */

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: var(--header-h);
  padding: 0 12px;
  padding-top: var(--safe-top);
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-bg);
}

.app-header h1 { font-size: 1.2rem; margin: 0; color: var(--header-ink); }

.app-header .logo { height: 32px; display: block; }

.icon-btn {
  background: transparent;
  color: var(--header-ink);
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  line-height: 1;
}

.icon-btn:active { background: rgba(255,255,255,0.12); }

/* Dropdown menu triggered from the header */
.header-menu {
  position: fixed;
  top: calc(var(--header-h) + var(--safe-top));
  right: 10px;
  left: 10px;
  z-index: 29;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: none;
  flex-direction: column;
  gap: 10px;
}

.header-menu.open { display: flex; }

.header-menu select { margin: 0; }

.header-menu .menu-link {
  display: block;
  text-align: center;
  text-decoration: none;
  background: #eee;
  color: var(--ink);
  border-radius: 10px;
  padding: 12px 18px;
  font-weight: 700;
  font-size: 0.95rem;
}

.header-menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 28;
  background: rgba(0,0,0,0.15);
  display: none;
}

.header-menu-backdrop.open { display: block; }

.app-body {
  max-width: 1000px;
  margin: 0 auto;
  padding: 16px 14px calc(var(--nav-h) + var(--safe-bottom) + 24px);
}

/* Bottom app-style navigation */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  background: var(--panel);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
  padding-bottom: var(--safe-bottom);
  overflow-x: auto;
  scrollbar-width: none;
}

.bottom-nav::-webkit-scrollbar { display: none; }

.tab-btn {
  position: relative;
  flex: 1 1 0;
  min-width: 56px;
  background: transparent;
  border: none;
  border-radius: 0;
  color: var(--muted);
  padding: 8px 2px 6px;
  height: var(--nav-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-weight: 700;
}

.tab-btn .tab-icon { font-size: 1.3rem; line-height: 1; }
.tab-btn .tab-label {
  font-size: 0.65rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.tab-btn.active { color: var(--accent); }

.tab-btn .badge {
  position: absolute;
  top: 4px;
  right: 12px;
  margin-left: 0;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 10px;
}

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

.photo-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.photo-card .thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  cursor: crosshair;
  overflow: hidden;
  touch-action: manipulation;
}

.photo-card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #eee;
  pointer-events: none;
}

.photo-card .focus-marker {
  position: absolute;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  margin-top: -8px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 1px 4px rgba(0,0,0,0.5);
  pointer-events: none;
}

.photo-card .meta {
  padding: 8px 10px;
  font-size: 0.85rem;
}

.photo-card .meta .name { font-weight: 700; }

.photo-card .actions {
  padding: 0 10px 10px;
}

.photo-card .actions button { width: 100%; }

.form-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.form-row > div { flex: 1 1 100%; min-width: 140px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

/* Tables render as stacked cards on narrow screens (mobile-first default) */
table.list {
  display: block;
  width: 100%;
  border-collapse: collapse;
}

table.list thead { display: none; }
table.list tbody { display: block; }

table.list th {
  text-align: left;
  padding: 10px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

table.list tr {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 14px;
  margin-bottom: 12px;
}

table.list td {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: right;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

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

table.list td[data-label]::before {
  content: attr(data-label);
  font-weight: 700;
  color: var(--muted);
  text-align: left;
  margin-right: auto;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

table.list td select,
table.list td input[type=text].edit-mode {
  width: auto;
  max-width: 60%;
}

table.list td.cell-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 0;
}

.subtab-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.subtab-btn {
  background: #eee;
  color: var(--ink);
  border: none;
  border-radius: 999px;
  padding: 9px 16px;
  font-weight: 700;
  font-size: 0.85rem;
}

.subtab-btn.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.subtab-panel { display: none; }
.subtab-panel.active { display: block; }

.subtab-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* ===== Modals ===== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(20, 20, 10, 0.45);
  display: none;
}

.modal-backdrop.open { display: block; }

.modal {
  display: none;
  position: fixed;
  z-index: 51;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  opacity: 0;
  width: calc(100% - 32px);
  max-width: 460px;
  max-height: calc(100% - 32px);
  overflow-y: auto;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.modal.open {
  display: block;
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.modal-header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { margin: 0; font-size: 1.1rem; }

.modal-close {
  background: transparent;
  color: var(--muted);
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.3rem;
  line-height: 1;
  flex: 0 0 auto;
}

.modal-close:active { background: #eee; }

.modal-body { padding: 18px; }
.modal-body > .btn-primary:last-of-type { margin-bottom: 0; }

body.modal-open { overflow: hidden; }

.settings-layout {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.settings-form { flex: 1 1 100%; min-width: 260px; }
.settings-preview { flex: 1 1 100%; min-width: 260px; }

/* Kiosk-style preview, mirrors device/kiosk/css/style.css look */
.frame-preview {
  aspect-ratio: 4 / 3;
  border-radius: 14px;
  overflow: hidden;
  position: relative;
  background: #0d1b2a;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  border: 8px solid #1b1b1b;
}

.frame-preview img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.55;
}

.frame-preview .content {
  position: relative;
  z-index: 1;
}

.frame-preview .greeting { font-size: 1.4em; margin-bottom: 6px; }
.frame-preview .reminder {
  margin-top: 14px;
  background: rgba(0,0,0,0.4);
  padding: 8px 14px;
  border-radius: 8px;
  display: inline-block;
}

.empty-state {
  padding: 30px 16px;
  text-align: center;
  color: var(--muted);
}

.badge {
  display: inline-block;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 4px;
  vertical-align: middle;
}

.voice-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.saved-message-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 10px;
}

.play-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  font-size: 0.95rem;
  padding: 0;
  cursor: pointer;
}

.play-btn.playing { background: var(--danger); }

.saved-message-info {
  flex: 1;
  min-width: 0;
}

.saved-message-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-menu {
  position: relative;
  flex: 0 0 auto;
}

.saved-menu-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  padding: 0;
}

.saved-menu-btn:hover, .saved-menu-btn:focus { background: #eee; }

.saved-menu-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: 42px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.15);
  min-width: 140px;
  z-index: 5;
  overflow: hidden;
}

.saved-menu-dropdown.open { display: block; }

.saved-menu-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 0;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--danger);
}

.saved-menu-dropdown button:hover { background: #fbe6e3; }

.voice-card .transcript {
  font-style: italic;
  color: var(--muted);
  margin: 6px 0 14px;
}

.voice-card audio {
  width: 100%;
  margin-bottom: 14px;
}

.voice-card .actions-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

.voice-card .actions-row button,
.voice-card .actions-row a {
  width: 100%;
  margin-top: 0;
}

.category-badge {
  background: var(--accent);
  margin-left: 0;
  margin-right: 8px;
}

table.list button {
  width: auto;
  margin-top: 0;
}

.status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: capitalize;
}

.status-pill.status-active { background: #e2f2e8; color: #1c5c3e; }
.status-pill.status-offline { background: #fbe6e3; color: var(--danger); }
.status-pill.status-unpaired { background: #eee; color: var(--muted); }
.status-pill.status-success { background: #e2f2e8; color: #1c5c3e; }
.status-pill.status-failed { background: #fbe6e3; color: var(--danger); }

.stat-tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-tile .value { font-size: 1.6rem; font-weight: 700; }
.stat-tile .label { color: var(--muted); font-size: 0.85rem; }

.storage-meter-bar {
  background: #eee;
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
  margin: 10px 0;
}

.storage-meter-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.storage-meter-fill.at-limit { background: var(--danger); }

.storage-limit-banner {
  background: #fbe6e3;
  color: var(--danger);
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 12px;
}

.storage-limit-banner .btn-secondary {
  margin-top: 10px;
}

/* A horizontally-scrollable wrapper for data-dense admin tables that stay
   real tables even on mobile (superadmin logs) instead of becoming cards. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -2px 12px;
  padding: 0 2px;
}

.table-scroll table.list {
  display: table;
  min-width: 640px;
}

.table-scroll table.list thead { display: table-header-group; }
.table-scroll table.list tbody { display: table-row-group; }
.table-scroll table.list tr {
  display: table-row;
  background: none;
  border: none;
  border-radius: 0;
  margin-bottom: 0;
  padding: 0;
}
.table-scroll table.list td {
  display: table-cell;
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.table-scroll table.list td::before { content: none; }
.table-scroll table.list tbody tr:hover td { background: rgba(46, 107, 79, 0.05); }

/* ===== Wider screens: relax the mobile card layout back into a
   traditional desktop dashboard ===== */
@media (min-width: 760px) {
  .app-header { padding: 0 28px; }
  .app-header .logo { height: 40px; }
  .app-body { padding: 24px 20px 60px; }

  .header-menu {
    position: static;
    display: flex !important;
    flex-direction: row;
    align-items: center;
    background: none;
    border: none;
    box-shadow: none;
    padding: 0;
    gap: 10px;
    width: auto;
  }

  .header-menu select { width: auto; }
  .header-menu .menu-link { padding: 8px 12px; }
  .header-menu-backdrop { display: none !important; }
  #menu-toggle { display: none; }

  .bottom-nav {
    position: static;
    box-shadow: none;
    border-top: none;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
    margin-bottom: 20px;
    overflow: visible;
  }

  .tab-btn {
    flex: 0 0 auto;
    flex-direction: row;
    height: auto;
    padding: 10px 14px;
    gap: 6px;
    border-bottom: 3px solid transparent;
  }

  .tab-btn.active { border-bottom-color: var(--accent); }
  .tab-btn .tab-icon { font-size: 1rem; }
  .tab-btn .tab-label { font-size: 0.9rem; }
  .tab-btn .badge { position: static; margin-left: 4px; }

  .form-row > div { flex: 1; min-width: 140px; }

  .settings-form { flex: 1 1 320px; }
  .settings-preview { flex: 1 1 320px; }

  table.list {
    display: table;
  }
  table.list thead { display: table-header-group; }
  table.list tbody { display: table-row-group; }
  table.list tr {
    display: table-row;
    background: none;
    border: none;
    border-radius: 0;
    margin-bottom: 0;
    padding: 0;
  }
  table.list td {
    display: table-cell;
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
  }
  table.list tbody tr:hover td { background: rgba(46, 107, 79, 0.05); }
  table.list td[data-label]::before { content: none; }
  table.list td.cell-actions {
    display: table-cell;
    padding: 10px 8px;
  }
  table.list td.cell-actions button { margin: 2px 0; }
  table.list td.cell-actions button + button { margin-left: 8px; }
  table.list td select,
  table.list td input[type=text].edit-mode { max-width: none; }

  .table-scroll table.list { min-width: 0; }

  .voice-card .actions-row { flex-direction: row; }
  .voice-card .actions-row button,
  .voice-card .actions-row a { width: auto; }

  .photo-card .actions button { width: auto; }
}
