:root {
  --paper: #f2ece1;
  --surface: #fffdf8;
  --ink: #26211d;
  --muted: #74695f;
  --wine: #762e28;
  --wine-dark: #4c1d1a;
  --gold: #b69462;
  --green: #3d6856;
  --amber: #9a642e;
  --line: rgba(53, 43, 35, .19);
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --sans: "Avenir Next", Avenir, "Helvetica Neue", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 8% 2%, rgba(182, 148, 98, .18), transparent 25rem),
    var(--paper);
  color: var(--ink);
  font-family: var(--sans);
}

button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.eyebrow,
th,
.metric-label {
  font: 700 .65rem/1.25 var(--mono);
  letter-spacing: .14em;
  text-transform: uppercase;
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 560px);
  padding: clamp(34px, 7vw, 68px);
  border: 1px solid var(--gold);
  background: rgba(255, 253, 248, .82);
  box-shadow: 0 34px 100px rgba(62, 42, 31, .14);
}

.login-card h1,
.dashboard-head h1,
.panel h2,
.dialog-head h2 {
  font-family: var(--serif);
  font-weight: 400;
}

.login-card h1 {
  margin: 12px 0 20px;
  font-size: clamp(4rem, 12vw, 7rem);
  line-height: .82;
  letter-spacing: -.055em;
}

.login-card > p { color: var(--muted); line-height: 1.65; }
.login-card form { display: grid; gap: 10px; margin-top: 30px; }

label {
  color: var(--muted);
  font: 700 .65rem/1.4 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 48px;
  margin-top: 7px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(182, 148, 98, .48);
  outline-offset: 2px;
}

.login-card button,
.primary-button,
.secondary-button {
  min-height: 48px;
  padding: 12px 18px;
  border: 1px solid var(--wine);
  background: var(--wine);
  color: white;
  font: 700 .67rem/1 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.login-card button { margin-top: 8px; }
.login-status { min-height: 24px; margin-bottom: 0; color: var(--wine) !important; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  min-height: 80px;
  padding: 14px clamp(20px, 4vw, 64px);
  border-bottom: 1px solid var(--line);
  background: rgba(242, 236, 225, .93);
  backdrop-filter: blur(16px);
}

.wordmark { margin-top: 3px; font: 400 1.45rem/1 var(--serif); }
.topbar-actions, .head-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.sync-state { color: var(--muted); font: 600 .62rem/1.3 var(--mono); text-transform: uppercase; }
.sync-state.connected { color: var(--green); }

.quiet-button {
  padding: 8px 11px;
  border: 0;
  border-bottom: 1px solid currentColor;
  background: transparent;
  color: var(--ink);
  font: 700 .62rem/1 var(--mono);
  letter-spacing: .06em;
  text-transform: uppercase;
}

main { width: min(100% - 40px, 1440px); margin-inline: auto; }

.dashboard-head {
  display: flex;
  justify-content: space-between;
  gap: 44px;
  align-items: end;
  padding: clamp(58px, 8vw, 112px) 0 52px;
}

.dashboard-head h1 {
  margin: 14px 0 0;
  font-size: clamp(4.5rem, 9vw, 9rem);
  line-height: .78;
  letter-spacing: -.06em;
}

.dashboard-head h1 em { color: var(--wine); font-weight: 400; }
.secondary-button { background: transparent; color: var(--wine); }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, .56);
}

.metrics article {
  min-height: 126px;
  padding: 24px;
  border-right: 1px solid var(--line);
}

.metrics article:last-child { border-right: 0; }
.metrics span { display: block; color: var(--muted); font: 700 .62rem/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.metrics strong { display: block; margin-top: 18px; font: 400 clamp(2rem, 4vw, 3.7rem)/1 var(--serif); }

.panel {
  margin-top: 42px;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, .7);
}

.purchase-panel { margin-bottom: 52px; }

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 28px;
  align-items: end;
  padding: 24px 26px;
  border-bottom: 1px solid var(--line);
}

.panel h2 { margin: 7px 0 0; font-size: clamp(2rem, 4vw, 3.4rem); line-height: .9; }
.panel-note { color: var(--muted); font-size: .82rem; }

.search { width: min(100%, 320px); }
.search span { display: block; }
.search input { min-height: 42px; }
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

th, td {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th { color: var(--muted); background: rgba(182, 148, 98, .06); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(182, 148, 98, .06); }
.film-name { font-family: var(--serif); font-size: 1.35rem; }
.film-meta, .cell-note { display: block; margin-top: 4px; color: var(--muted); font-size: .72rem; }
.remaining-time { display: block; color: var(--ink); font: 700 .78rem/1.25 var(--mono); white-space: nowrap; }
.expiration-time { display: block; max-width: 190px; margin-top: 5px; color: var(--muted); font-size: .68rem; line-height: 1.35; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: 700 .65rem/1 var(--mono);
  letter-spacing: .05em;
  text-transform: uppercase;
}

.status::before { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); content: ""; }
.status.active::before { background: var(--green); }
.status.expired::before { background: var(--wine); }
.status.not-started::before { background: var(--gold); }
.status.not-activated::before,
.status.reset::before { background: var(--gold); }
.status.unavailable::before { background: var(--amber); }

.row-actions { display: flex; justify-content: flex-end; gap: 7px; }
.row-actions button,
.row-actions a {
  min-height: 36px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font: 700 .59rem/1 var(--mono);
  letter-spacing: .04em;
  text-decoration: none;
  text-transform: uppercase;
  white-space: nowrap;
}

.row-actions button:hover,
.row-actions a:hover { border-color: var(--wine); color: var(--wine); }
.row-actions .purchase-action {
  border-color: var(--wine);
  background: var(--wine);
  color: white;
}
.row-actions .purchase-action:hover {
  background: var(--wine-dark);
  color: white;
}

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

footer {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  width: min(100% - 40px, 1440px);
  margin-inline: auto;
  padding: 0 0 38px;
  color: var(--muted);
  font: 600 .62rem/1.5 var(--mono);
  letter-spacing: .05em;
  text-transform: uppercase;
}

dialog {
  width: min(760px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  padding: 0;
  border: 1px solid var(--gold);
  background: var(--surface);
  color: var(--ink);
  overflow: auto;
  box-shadow: 0 30px 100px rgba(0, 0, 0, .36);
}

dialog::backdrop { background: rgba(28, 23, 20, .72); backdrop-filter: blur(5px); }
.dialog-form { padding: clamp(24px, 5vw, 46px); }
.dialog-head { display: flex; justify-content: space-between; gap: 24px; align-items: start; margin-bottom: 30px; }
.dialog-head h2 { margin: 7px 0 0; font-size: clamp(2.6rem, 7vw, 4.6rem); line-height: .9; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 50%; background: transparent; font-size: 1.4rem; }
.form-intro { max-width: 650px; margin: -10px 0 30px; color: var(--muted); line-height: 1.65; }
.mode-banner { display: grid; gap: 5px; margin: -8px 0 30px; padding: 18px 20px; border-left: 4px solid var(--green); background: rgba(61, 104, 86, .09); }
.mode-banner strong { color: var(--green); font: 700 .67rem/1.3 var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.mode-banner span, .fieldset-note { color: var(--muted); font-size: .82rem; line-height: 1.55; }
fieldset { padding: 24px; margin: 0 0 20px; border: 1px solid var(--line); }
legend { padding: 0 10px; color: var(--wine); font: 700 .64rem/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.fieldset-note { margin: 0 0 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-assurance { margin: 0 0 22px; padding: 16px 18px; border-left: 3px solid var(--gold); background: rgba(182, 148, 98, .09); color: var(--muted); font-size: .83rem; line-height: 1.6; }
.timing-readout { display: grid; gap: 7px; margin-bottom: 22px; padding: 22px; border: 1px solid var(--gold); background: rgba(182, 148, 98, .08); }
.timing-readout span { color: var(--muted); font: 700 .62rem/1 var(--mono); letter-spacing: .09em; text-transform: uppercase; }
.timing-readout strong { font: 400 clamp(2.2rem, 7vw, 4rem)/.95 var(--serif); }
.timing-readout small { color: var(--muted); font-size: .78rem; }
.timing-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 14px; }
.timing-presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 28px; }
.timing-presets button { padding: 9px 12px; border: 1px solid var(--line); background: transparent; color: var(--ink); font: 700 .6rem/1 var(--mono); letter-spacing: .04em; text-transform: uppercase; }
.timing-presets button:hover { border-color: var(--wine); color: var(--wine); }
.purchased-readout { border-color: var(--green); background: rgba(61, 104, 86, .08); }
.purchase-access-fields { margin-bottom: 18px; }
.purchase-access-actions { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }
.purchase-access-actions .primary-button { flex: 1 1 230px; }
.danger-button {
  min-height: 48px;
  padding: 12px 18px;
  border: 1px solid var(--wine);
  background: transparent;
  color: var(--wine);
  font: 700 .67rem/1 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
}
.danger-button:disabled,
.secondary-button:disabled { cursor: not-allowed; opacity: .45; }
.created-links { display: grid; gap: 18px; margin-bottom: 24px; }
.copy-field { display: grid; grid-template-columns: 1fr auto; margin-top: 7px; }
.copy-field input { margin: 0; }
.copy-field button { min-width: 74px; border: 1px solid var(--wine); background: var(--wine); color: white; font: 700 .62rem/1 var(--mono); text-transform: uppercase; }
.primary-link { display: inline-flex; padding: 16px 18px; background: var(--wine); color: white; font: 700 .65rem/1 var(--mono); letter-spacing: .07em; text-decoration: none; text-transform: uppercase; }
.metadata-editor { width: 100%; min-height: 430px; margin-bottom: 20px; padding: 16px; border: 1px solid var(--line); background: #211d1a; color: #f4ede4; font: 500 .75rem/1.6 var(--mono); resize: vertical; }
.toast { position: fixed; z-index: 50; right: 20px; bottom: 20px; max-width: 420px; padding: 16px 20px; background: var(--ink); color: white; box-shadow: 0 15px 50px rgba(0,0,0,.24); }
.toast.error { background: var(--wine); }
@media (max-width: 900px) {
  .dashboard-head { align-items: flex-start; flex-direction: column; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metrics article:nth-child(2) { border-right: 0; }
  .metrics article:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 620px) {
  main, footer { width: min(100% - 28px, 1440px); }
  .topbar { align-items: flex-start; flex-direction: column; }
  .dashboard-head h1 { font-size: clamp(4rem, 22vw, 6.5rem); }
  .metrics { grid-template-columns: 1fr; }
  .metrics article { border-right: 0; border-bottom: 1px solid var(--line); }
  .metrics article:last-child { border-bottom: 0; }
  .panel-head, footer { align-items: flex-start; flex-direction: column; }
  .search { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .timing-fields { grid-template-columns: 1fr; }
}
