:root {
  --brand: #1f4e79;
  --brand-dark: #173a5a;
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #1d2939;
  --muted: #667085;
  --border: #d0d5dd;
  --ok: #1e7b34;
  --ok-bg: #e7f6ec;
  --danger: #b42318;
  --past: #b54708;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--brand);
  color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 12px 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.title { flex: 1; min-width: 0; }

h1 { margin: 0; font-size: 1.2rem; }

.date-label {
  margin: 2px 0 0;
  font-size: 0.82rem;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clock {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.date-bar {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 10px;
  padding: 6px;
  border-radius: 10px;
  background: var(--brand-dark);
}

.date-bar.is-past { background: var(--past); }

.date-bar input {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  padding: 7px 4px;
  border-radius: 8px;
  border: none;
}

.nav-btn {
  width: 30px;
  height: 36px;
  flex: none;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
}

.nav-btn:disabled { opacity: 0.35; }

.today-btn {
  flex: none;
  border: none;
  border-radius: 8px;
  padding: 9px 6px;
  background: #fff;
  color: var(--past);
  font-weight: 700;
  font-size: 0.8rem;
}

.file-btn {
  flex: none;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 9px 7px;
  border-radius: 8px;
}

.file-excel { background: #1d6f42; }
.file-pdf { background: #c0392b; }

.filters {
  display: flex;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 10px;
}

.filter-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: #fff;
  padding: 8px 4px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
}

.filter-btn span {
  display: inline-block;
  min-width: 22px;
  margin-left: 3px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  font-size: 0.8rem;
}

.filter-btn.is-active { background: #fff; color: var(--brand); }
.filter-btn.is-active span { background: #e4ecf5; }

.search { position: relative; }

.search input {
  width: 100%;
  font-size: 16px; /* prevents iOS zoom on focus */
  padding: 12px 44px 12px 14px;
  border-radius: 10px;
  border: none;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.search input::-webkit-search-cancel-button { display: none; }

.clear-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  border: none;
  background: transparent;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--muted);
}

main {
  padding: 12px 12px calc(24px + env(safe-area-inset-bottom));
}

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

.card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  min-height: 78px;
  padding: 12px;
  text-align: left;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.2s ease;
}

.card:active:not(:disabled) { transform: scale(0.97); background: #eef3f9; }

.card-name {
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.2;
  word-break: break-word;
}

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

.card.is-checked {
  background: var(--ok-bg);
  border-color: #a6d9b5;
}

.card.is-checked:active { background: #d5efdd; }

.card.is-checked .card-name { color: #3d4b5c; }

.card.is-checked .card-status {
  color: var(--ok);
  font-weight: 700;
  font-size: 1rem;
}

.card.is-pending { opacity: 0.6; }

.empty {
  text-align: center;
  color: var(--muted);
  margin-top: 40px;
}

.dialog {
  width: min(92vw, 380px);
  padding: 0;
  border: none;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

.dialog::backdrop { background: rgba(16, 24, 40, 0.5); }

.dialog-body { padding: 18px; }

.dialog-body h2 { margin: 0; font-size: 1.15rem; }

.dialog-sub { margin: 4px 0 16px; color: var(--muted); font-size: 0.9rem; }

.time-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
  font-size: 0.9rem;
}

.time-field input {
  font-size: 1.4rem;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
}

.spacer { flex: 1; }

.dlg-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 9px;
  padding: 10px 14px;
  font-weight: 600;
}

.dlg-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.dlg-danger { color: var(--danger); border-color: #f3b4ae; }
.dlg-btn:disabled { opacity: 0.6; }

.toast {
  display: flex;
  align-items: center;
  gap: 14px;
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: #1d2939;
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.95rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  z-index: 20;
}

.toast.is-error { background: var(--danger); }

.toast[hidden] { display: none; }

.toast-action {
  flex: none;
  border: none;
  background: transparent;
  color: #8ec5ff;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 4px 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ---------- Menu ---------- */

.menu { position: relative; }

.menu-btn {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 9px;
  background: transparent;
  color: #fff;
  font-size: 1.2rem;
  line-height: 1;
}

.menu-list {
  position: absolute;
  right: 0;
  top: 44px;
  min-width: 200px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  padding: 6px;
  z-index: 30;
}

.menu-list a,
.menu-list button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.menu-list a:active,
.menu-list button:active { background: #eef3f9; }

.menu-list button { color: var(--danger); }

/* ---------- Secondary pages ---------- */

.page-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.back-link {
  color: #fff;
  text-decoration: none;
  font-size: 1.6rem;
  line-height: 1;
  padding: 2px 8px 4px 0;
}

.page-header h1 { flex: 1; }

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

.panel h2 { margin: 0 0 10px; font-size: 1rem; }

.field-row { display: flex; gap: 8px; flex-wrap: wrap; }

.field-row input {
  flex: 1 1 120px;
  min-width: 0;
  font-size: 16px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
}

.primary-btn {
  border: none;
  border-radius: 9px;
  padding: 10px 16px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}

.primary-btn:disabled { opacity: 0.6; }

.list { display: flex; flex-direction: column; gap: 8px; }

.list-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.list-row.is-inactive { background: #f2f4f7; color: var(--muted); }

.list-row .row-main { flex: 1; min-width: 0; }

.row-name { font-weight: 700; word-break: break-word; }

.row-sub { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }

.row-btn {
  flex: none;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.row-btn.danger { color: var(--danger); border-color: #f3b4ae; }
.row-btn.ok { color: var(--ok); border-color: #a6d9b5; }

.section-title {
  margin: 18px 0 8px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}

.date-range {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.date-range label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 600;
}

.date-range input {
  font-size: 16px;
  padding: 9px 6px;
  border: 1px solid var(--border);
  border-radius: 9px;
  min-width: 0;
}

.presets { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

.preset-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--brand);
}

.download-row { display: flex; gap: 8px; margin-top: 12px; }

.download-row a {
  flex: 1;
  text-align: center;
  text-decoration: none;
  color: #fff;
  font-weight: 700;
  padding: 11px 8px;
  border-radius: 9px;
}

.stat {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.stat small { display: block; font-weight: 500; color: var(--muted); }

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

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--brand);
}

.login-card {
  width: min(100%, 340px);
  background: #fff;
  border-radius: 16px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

.login-card img { width: 72px; height: 72px; border-radius: 16px; }

.login-card h1 { margin: 12px 0 4px; color: var(--brand); }

.login-card p { margin: 0 0 18px; color: var(--muted); }

.login-card input {
  width: 100%;
  font-size: 1.6rem;
  letter-spacing: 8px;
  text-align: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 12px;
}

.login-card .primary-btn { width: 100%; padding: 13px; font-size: 1rem; }

.login-error { color: var(--danger); min-height: 1.2em; margin-top: 10px; font-size: 0.9rem; }
