/* pintas UI — identitas: kertas + stempel.
   Satu accent (burnt orange) dipakai hanya untuk aksi utama, fokus, dan data.
   Sisanya ink di atas kertas. Tanpa dependency, tanpa build step. */

:root {
  --paper: #f7f5f2;
  --card: #ffffff;
  --ink: #17181a;
  --muted: #6b6862;
  --line: #e2ddd6;
  --accent: #b45309;
  --accent-hover: #92400e;
  --accent-soft: #fdf6ec;
  --danger: #b91c1c;
  --danger-soft: #fbeeec;
  --neutral-soft: #f1efe9;
  --radius-card: 10px;
  --radius-control: 8px;
  --control-h: 38px;
  --shadow-float: 0 6px 20px rgba(23, 24, 26, .12);
}

* { box-sizing: border-box; }

/* Atribut hidden harus menang atas display dari kelas seperti .stack/.auth-view. */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0 0 .75rem; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: .95rem; font-weight: 600; margin: 1.5rem 0 .5rem; }

a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 2px;
}

a:hover { text-decoration-color: currentColor; }

.muted { color: var(--muted); }
.error { color: var(--danger); margin: .75rem 0 0; font-size: .9rem; }
.hint { color: var(--muted); font-size: .78rem; font-weight: 400; }
.hint.is-error { color: var(--danger); }

/* ---------- Auth ---------- */

.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-float);
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  margin: 0 0 .15rem;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 26px;
  height: 26px;
  color: var(--accent);
  flex: none;
}

.brand-name {
  font-size: 1.6rem;
  font-weight: 200;
  letter-spacing: -.01em;
  line-height: 1;
}

.topbar-brand .brand-mark { width: 20px; height: 20px; }
.topbar-brand .brand-name { font-size: 1rem; }

.tabs {
  display: flex;
  gap: .25rem;
  background: var(--paper);
  padding: .25rem;
  border-radius: var(--radius-control);
  margin: 1.25rem 0 1rem;
}

.tab {
  flex: 1;
  border: 0;
  background: transparent;
  padding: .5rem;
  border-radius: 6px;
  font: inherit;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}

.tab.is-active {
  background: var(--card);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
}

/* ---------- Layout ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .875rem 1.25rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.topbar-right { display: flex; align-items: center; gap: .75rem; }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem;
  display: grid;
  gap: 1.25rem;
}

/* Kartu flat: hanya border. Shadow disimpan untuk elemen yang benar-benar
   mengapung (toast, kartu auth). */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 1.25rem;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .75rem;
}

.section-head h2 { margin: 0; }

/* ---------- Form ---------- */

.stack { display: grid; gap: .875rem; text-align: left; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .875rem;
}

.grid .span-2 { grid-column: 1 / -1; }

.field { display: grid; gap: .6rem; }

/* Checkbox punya tampilan sendiri, bukan kontrol 38px selebar kolom. */
.check {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  font-weight: 500;
  color: #3a3a38;
  cursor: pointer;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  padding: 0;
  margin: 0;
  accent-color: var(--accent);
  flex: none;
}

.chips { display: flex; flex-wrap: wrap; gap: .4rem; }

.chip {
  font: inherit;
  font-size: .82rem;
  font-weight: 500;
  padding: .35rem .7rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}

.chip:hover { background: var(--paper); }

.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.expiry-controls { display: grid; gap: .5rem; justify-items: start; }
.expiry-controls input[type="datetime-local"] { max-width: 260px; }

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

label {
  display: grid;
  align-content: start;
  gap: .35rem;
  font-size: .85rem;
  font-weight: 500;
  color: #3a3a38;
}

input {
  font: inherit;
  font-size: .9rem;
  height: var(--control-h);
  padding: 0 .65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--card);
  color: var(--ink);
  width: 100%;
}

/* Input native (datetime-local) punya tinggi intrinsik sendiri; samakan. */
input[type="datetime-local"] { line-height: normal; }

input:focus-visible,
.btn:focus-visible,
.bar:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  font: inherit;
  font-size: .9rem;
  font-weight: 500;
  height: var(--control-h);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  padding: 0 1rem;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
  white-space: nowrap;
}

.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }

.btn.ghost {
  background: var(--card);
  border-color: var(--line);
  color: var(--ink);
}

.btn.ghost:hover { background: var(--paper); }

.btn.small { height: auto; padding: .35rem .65rem; font-size: .82rem; }

.btn.danger { background: var(--card); border-color: #e7c9c4; color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }

.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Table ---------- */

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

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

th, td {
  text-align: left;
  padding: .6rem .5rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

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

tbody tr:last-child td { border-bottom: 0; }

td.num, th.num { text-align: right; }
th.actions-col, td.actions-cell { text-align: right; }

/* td tetap table-cell; flex hanya di wrapper dalamnya. */
.actions-inner {
  display: flex;
  gap: .35rem;
  justify-content: flex-end;
}

.code-cell { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 600; }

.target-cell {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.badge {
  display: inline-block;
  padding: .1rem .5rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}

.badge.ok { background: var(--neutral-soft); color: var(--ink); }
.badge.expired { background: var(--danger-soft); color: var(--danger); }

/* Badge status + sisa waktu di bawahnya. Catatan digeser sejauh padding
   horizontal badge supaya teks keduanya rata kiri. */
.status { display: grid; gap: .15rem; justify-items: start; }
.status-note { font-size: .78rem; color: var(--muted); white-space: nowrap; padding-left: .5rem; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: .75rem;
}

/* ---------- State ---------- */

.state {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  margin: .25rem 0;
  color: var(--muted);
  font-size: .9rem;
}

.state.is-error { color: var(--danger); }

/* ---------- Stats ---------- */

.stats-grid { display: flex; gap: 1rem; flex-wrap: wrap; }

.stat {
  flex: 1 1 140px;
  background: var(--paper);
  border-radius: var(--radius-control);
  padding: .875rem 1rem;
}

.stat-value { display: block; font-size: 1.5rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: .8rem; }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 140px;
  padding-top: .5rem;
  border-bottom: 1px solid var(--line);
}

.bar {
  flex: 1;
  min-width: 6px;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  position: relative;
  min-height: 2px;
}

.bar[data-empty="true"] { background: var(--line); }

.bar:hover::after,
.bar:focus-visible::after {
  content: attr(data-label);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translate(-50%, -4px);
  background: var(--ink);
  color: var(--paper);
  font-size: .7rem;
  padding: .15rem .4rem;
  border-radius: 4px;
  white-space: nowrap;
  z-index: 1;
}

.chart-summary { margin: .5rem 0 0; font-size: .82rem; }

.refs { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }

.refs li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: .45rem .6rem;
  background: var(--paper);
  border-radius: 6px;
  font-size: .85rem;
}

.refs .ref-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: .6rem 1rem;
  border-radius: var(--radius-control);
  font-size: .875rem;
  box-shadow: var(--shadow-float);
  z-index: 10;
  max-width: calc(100vw - 2rem);
}

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

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
  .container { padding: .875rem; }
  .card { padding: 1rem; }
  .target-cell { max-width: 120px; }
  .topbar { padding: .75rem .875rem; }
  #user-email { display: none; }
}
