/* epson-reset admin — shared stylesheet. Local-only, no external fonts/CDNs. */

:root {
  --color-bg: #F5F7FA;
  --color-surface: #FFFFFF;
  --color-text: #1F2937;
  --color-text-muted: #6B7280;
  --color-border: #E5E7EB;
  --color-accent: #3B6FD6;
  --color-accent-weak: #EAF0FC;
  --color-success: #2F8A5A;
  --color-success-weak: #E7F5EC;
  --color-warning: #B98900;
  --color-warning-weak: #FDF3DA;
  --color-danger: #C0392B;
  --color-danger-weak: #FBEAE8;
  --color-neutral: #6B7280;
  --color-neutral-weak: #EEF0F2;
  --sidebar-width: 220px;
  --radius: 10px;
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

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

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

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

h1, h2, h3 { margin: 0 0 0.5rem 0; font-weight: 600; color: var(--color-text); }
h1 { font-size: 1.25rem; }
h2 { font-size: 1rem; margin-top: 0; }

code, .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
}

/* ---------- Auth pages (login / 2fa) ---------- */

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 2rem;
}

.auth-card h1 {
  font-size: 1.1rem;
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-brand {
  display: flex;
  justify-content: center;
  color: var(--color-accent);
  margin-bottom: 0.75rem;
}

.auth-subtext {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  text-align: center;
  margin: -0.75rem 0 1.25rem 0;
}

.auth-hint {
  color: var(--color-text-muted);
  font-size: 0.78rem;
  text-align: center;
  margin: 1rem 0 0 0;
}

@media (max-width: 360px) {
  .auth-card { padding: 1.5rem 1.25rem; }
}

/* ---------- App shell (sidebar + topbar + content) ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: 1rem 0.75rem;
}

.sidebar-brand {
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.5rem 0.5rem 1rem 0.5rem;
  color: var(--color-text);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  color: var(--color-text-muted);
  font-size: 0.88rem;
  font-weight: 500;
}

.nav-subitem {
  padding-left: 1.8rem;
  font-size: 0.82rem;
  font-weight: 400;
}

.nav-item:hover {
  background: var(--color-neutral-weak);
  text-decoration: none;
  color: var(--color-text);
}

.nav-item.active {
  background: var(--color-accent-weak);
  color: var(--color-accent);
}

.nav-item svg { flex-shrink: 0; width: 16px; height: 16px; }

.nav-group + .nav-group { margin-top: 0.9rem; }

.nav-group-label {
  padding: 0 0.6rem;
  margin-bottom: 0.2rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  opacity: 0.75;
}

.sidebar-logout {
  margin: 0;
  padding: 0;
}

.nav-item-button {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font: inherit;
  cursor: pointer;
  margin-top: 0;
}

.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1.5rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  min-width: 0;
}

/* Root-cause fix for the mobile overflow bug: flex children default to
   min-width:auto, which lets a long page title or admin email push the
   topbar (and therefore the document) wider than the viewport, forcing
   horizontal scroll before the hamburger/logout ever become reachable.
   min-width:0 lets these children shrink and truncate instead. */
.page-title {
  font-size: 1.05rem;
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  flex-shrink: 0;
  min-width: 0;
  max-width: 45vw;
}

.topbar-email {
  color: var(--color-text-muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-email:hover { color: var(--color-accent); }

.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-success);
  display: inline-block;
  flex-shrink: 0;
}

.hamburger-btn {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
}

.hamburger-btn svg { width: 20px; height: 20px; }

.content {
  padding: 1.5rem;
  max-width: 1200px;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* ---------- Cards ---------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.card + .card { margin-top: 0; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

/* ---------- KPI cards ---------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 0.9rem 1rem;
  border-top: 3px solid var(--kpi-accent, var(--color-accent));
}

.kpi-value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.kpi-label { font-size: 0.78rem; color: var(--color-text-muted); margin-top: 0.25rem; }

.kpi-card-link {
  display: block;
  color: inherit;
  text-decoration: none;
  transition: box-shadow 0.15s ease;
}
.kpi-card-link:hover .kpi-card { box-shadow: 0 0 0 2px var(--kpi-accent, var(--color-accent)); }

.kpi-card-warning { --kpi-accent: var(--color-danger); background: var(--color-danger-weak); }
.kpi-card-calm { --kpi-accent: var(--color-neutral); }

/* ---------- Status distribution bar ---------- */

.status-bar {
  display: flex;
  width: 100%;
  height: 10px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--color-neutral-weak);
  margin-bottom: 0.75rem;
}

.status-bar-segment { height: 100%; }

.status-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.status-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.35rem;
}

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

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

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

thead th {
  text-align: left;
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--color-border);
  padding: 0.55rem 0.75rem;
  white-space: nowrap;
}

tbody td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

tbody tr:hover { background: var(--color-neutral-weak); }
tbody tr:last-child td { border-bottom: none; }

.table-empty {
  color: var(--color-text-muted);
  text-align: center;
  padding: 1.5rem !important;
}

/* ---------- Badges ---------- */

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.6;
}

.badge-success { background: var(--color-success-weak); color: var(--color-success); }
.badge-info { background: var(--color-accent-weak); color: var(--color-accent); }
.badge-warning { background: var(--color-warning-weak); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-weak); color: var(--color-danger); }
.badge-neutral { background: var(--color-neutral-weak); color: var(--color-neutral); }

/* ---------- Alerts ---------- */

.alert {
  border-radius: 8px;
  padding: 0.65rem 0.9rem;
  font-size: 0.86rem;
  margin-bottom: 1rem;
  border: 1px solid transparent;
}

.alert-success { background: var(--color-success-weak); color: var(--color-success); border-color: rgba(47,138,90,0.25); }
.alert-warning { background: var(--color-warning-weak); color: var(--color-warning); border-color: rgba(185,137,0,0.25); }
.alert-danger { background: var(--color-danger-weak); color: var(--color-danger); border-color: rgba(192,57,43,0.25); }
.alert-info { background: var(--color-accent-weak); color: var(--color-accent); border-color: rgba(59,111,214,0.25); }

/* ---------- Forms & buttons ---------- */

label { display: block; margin-bottom: 0.9rem; font-size: 0.85rem; color: var(--color-text); }
label > span, label .label-text { display: block; margin-bottom: 0.3rem; color: var(--color-text-muted); font-size: 0.8rem; }

input[type=text], input[type=password], input[type=email], select {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 0.88rem;
  background: var(--color-surface);
  color: var(--color-text);
}

input:focus, select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-weak);
}

button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--color-accent);
  background: var(--color-accent);
  color: #fff;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

button:hover, .btn:hover { opacity: 0.92; text-decoration: none; }

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.toolbar label { margin-bottom: 0; min-width: 140px; }
.toolbar button { margin-bottom: 0; }

.field-hint { color: var(--color-text-muted); font-size: 0.78rem; margin-top: 0.25rem; }

.model-link { font-weight: 600; }

.section-danger {
  border: 1px solid rgba(192,57,43,0.3);
  background: var(--color-danger-weak);
}

.pagination {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-top: 0.75rem;
}

/* ---------- Password show/hide toggle ---------- */

.password-field {
  display: flex;
  align-items: stretch;
  gap: 0.4rem;
}

.password-field input { flex: 1 1 auto; min-width: 0; }

.password-toggle {
  flex-shrink: 0;
  background: var(--color-surface);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  padding: 0 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
}

.password-toggle:hover { color: var(--color-text); opacity: 1; }

/* ---------- Account page: 2FA / recovery codes ---------- */

.account-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

.field-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.86rem;
}

.field-row:last-child { border-bottom: none; }
.field-row-label { color: var(--color-text-muted); }
.field-row-value { text-align: right; word-break: break-word; }

.action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.recovery-codes-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 1rem 0;
  padding: 1rem;
  background: var(--color-neutral-weak);
  border-radius: 8px;
}

.recovery-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  text-align: center;
  padding: 0.35rem;
  background: var(--color-surface);
  border-radius: 6px;
  border: 1px solid var(--color-border);
}

.qr-wrap {
  display: flex;
  justify-content: center;
  padding: 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  margin: 1rem 0;
}

.qr-wrap img { width: 180px; height: 180px; }

.manual-key {
  display: block;
  text-align: center;
  padding: 0.6rem;
  background: var(--color-neutral-weak);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  word-break: break-all;
  margin: 0.5rem 0 1rem 0;
}

/* ---------- Responsive / mobile navigation ---------- */

@media (max-width: 980px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* True hamburger drawer replaces the old horizontal-scrolling top nav.
   The desktop sidebar is hidden entirely below this breakpoint; the topbar
   (hamburger + title + minimal right-side content) is always the visible
   entry point, and it is kept inside the viewport via the min-width:0 /
   flex-shrink:0 rules above rather than by hiding overflow. */
@media (max-width: 880px) {
  .sidebar { display: none; }
  .hamburger-btn { display: inline-flex; }
  .content { padding: 1rem; }
  .topbar { padding: 0.75rem 1rem; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar label { min-width: 0; }
  .recovery-codes-grid { grid-template-columns: 1fr; }
  .field-row { flex-direction: column; gap: 0.15rem; }
  .field-row-value { text-align: left; }
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  z-index: 40;
}

.mobile-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(280px, 85vw);
  max-width: 85vw;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  overflow-y: auto;
  box-sizing: border-box;
}

.mobile-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0.5rem 1rem 0.5rem;
}

.drawer-close-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.mobile-drawer-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.mobile-drawer-nav .nav-item { padding: 0.65rem 0.6rem; font-size: 0.92rem; }
.mobile-drawer-nav .sidebar-logout { margin-top: 0.5rem; border-top: 1px solid var(--color-border); padding-top: 0.5rem; }

body.drawer-open { overflow: hidden; }

/* Tap targets stay comfortably sized down to the narrowest tested width. */
@media (max-width: 480px) {
  .hamburger-btn { width: 40px; height: 40px; }
  .nav-item, button, .btn { min-height: 40px; }
}
