@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@400;600;700&family=Jost:wght@300;400;500&display=swap');

/* ── TOKENS ── */
:root {
  --ink: #1a1a2e;
  --paper: #f5f0e8;
  --accent: #8b1a1a;
  --accent-dark: #6d1515;
  --accent2: #c8a96e;
  --line: rgba(26, 26, 46, 0.15);
  --line-soft: rgba(26, 26, 46, 0.08);
  --field-bg: rgba(255, 255, 255, 0.7);
  --muted: #777;
  --muted-strong: #555;
  --error: #8b1a1a;
  --success: #2d7a2d;
  --radius: 2px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: 'Jost', 'Segoe UI', sans-serif;
  font-weight: 400;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  background-image:
    radial-gradient(
      ellipse at 10% 20%,
      rgba(139, 26, 26, 0.06) 0%,
      transparent 50%
    ),
    radial-gradient(
      ellipse at 90% 80%,
      rgba(200, 169, 110, 0.08) 0%,
      transparent 50%
    );
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
}

a {
  color: inherit;
}

/* ── AUTH SCREEN ── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-box {
  width: 360px;
  max-width: 100%;
  padding: 36px 40px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(26, 26, 46, 0.1);
  text-align: center;
  position: relative;
}

.auth-box .crest {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 13px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

.auth-box h1 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 24px;
  line-height: 1.2;
  color: var(--ink);
}

.auth-box h1 .title-line {
  display: block;
  text-align: center;
}

.auth-box h1 .title-line-sub {
  font-size: 0.85em;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.auth-box input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  background: var(--field-bg);
  font-family: 'Jost', sans-serif;
  font-size: 14px;
  color: var(--ink);
  outline: none;
  margin-bottom: 12px;
  border-radius: var(--radius);
  transition: border-color 0.2s;
  text-align: left;
}

.auth-box input::placeholder {
  color: #b6b6b6;
}

.auth-box input:focus {
  border-color: var(--accent);
  background: #fff;
}

.auth-error {
  color: var(--accent);
  font-size: 12px;
  margin-bottom: 12px;
  min-height: 16px;
  text-align: left;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--ink);
  color: #fff;
  border: none;
  font-family: 'Jost', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--radius);
  transition:
    background 0.2s,
    transform 0.1s;
}

.btn-primary:hover {
  background: var(--accent);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:disabled {
  background: #999;
  cursor: not-allowed;
}

/* ── APP SCREEN ── */
#app-screen {
  display: none;
  min-height: 100vh;
  padding-bottom: 96px; /* room for fixed generate-bar */
}

#app-screen.is-active {
  display: block;
}

header {
  border-bottom: 1px solid var(--line);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  line-height: 1.15;
}

.header-title span {
  display: block;
  color: var(--accent);
  font-size: 11px;
  font-family: 'Jost', sans-serif;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  font-weight: 400;
  margin-bottom: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 18px;
}

.header-link {
  font-family: 'Jost', sans-serif;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #888;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 4px;
  border-radius: var(--radius);
  transition: color 0.2s;
}

.header-link:hover {
  color: var(--accent);
}

.header-link.active {
  color: var(--ink);
  border-bottom: 1px solid var(--ink);
  padding-bottom: 4px;
}

.btn-logout {
  font-family: 'Jost', sans-serif;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #888;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius);
  transition: color 0.2s;
}

.btn-logout:hover {
  color: var(--accent);
}

/* ── MESSAGE BANNER ── */
.banner {
  margin: 0 0 16px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
  color: var(--muted-strong);
  border-radius: var(--radius);
}

.banner[data-kind='success'] {
  color: var(--success);
  border-color: rgba(45, 122, 45, 0.3);
}

.banner[data-kind='error'] {
  color: var(--error);
  border-color: rgba(139, 26, 26, 0.3);
}

.banner[hidden] {
  display: none;
}

/* ── MAIN VIEWS ── */
.main-content {
  max-width: 900px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

.view {
  display: block;
}

.view[hidden] {
  display: none;
}

/* ── SECTIONS ── */
.section {
  margin-bottom: 36px;
  background: #fff;
  border: 1px solid var(--line);
  overflow: hidden;
}

.section-header {
  padding: 14px 24px;
  background: var(--ink);
  color: #fff;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-body {
  padding: 24px;
}

.fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 24px;
}

.fields-grid.cols-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.field-full {
  grid-column: 1 / -1;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}

.field input,
.field select,
.field textarea {
  padding: 9px 12px;
  border: 1px solid var(--line);
  background: var(--field-bg);
  font-family: 'Jost', sans-serif;
  font-size: 14px;
  color: var(--ink);
  outline: none;
  border-radius: var(--radius);
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
  width: 100%;
}

.field input::placeholder,
.field textarea::placeholder {
  color: #b6b6b6;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px rgba(200, 169, 110, 0.15);
  background: #fff;
}

.field textarea {
  resize: vertical;
  min-height: 56px;
}

.field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ── DIVIDER ── */
.divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 20px 0;
}

/* ── DATE INPUT WITH CALENDAR EMOJI ── */
.date-wrap {
  position: relative;
}

.date-wrap input[type='date'] {
  cursor: pointer;
  color: var(--ink);
  padding-left: 36px;
  width: 100%;
}

.date-wrap::before {
  content: '📅';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  pointer-events: none;
  z-index: 1;
}

.date-wrap input[type='date']::-webkit-calendar-picker-indicator {
  position: absolute;
  left: 0;
  top: 0;
  width: 36px;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* ── GENERATE BAR ── */
.generate-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 30px rgba(26, 26, 46, 0.08);
  z-index: 10;
}

.generate-bar-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.generate-bar .status-msg {
  font-size: 13px;
  color: var(--muted-strong);
  display: flex;
  align-items: center;
  gap: 8px;
}

.generate-bar .status-msg.success {
  color: var(--success);
}

.generate-bar .status-msg.error {
  color: var(--accent);
}

#btn-generate {
  padding: 13px 40px;
  background: var(--accent);
  color: #fff;
  border: none;
  font-family: 'Jost', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--radius);
  transition:
    background 0.2s,
    transform 0.1s,
    box-shadow 0.2s;
  box-shadow: 0 4px 20px rgba(139, 26, 26, 0.3);
}

#btn-generate:hover {
  background: var(--accent-dark);
  box-shadow: 0 6px 25px rgba(139, 26, 26, 0.4);
}

#btn-generate:active {
  transform: scale(0.98);
}

#btn-generate:disabled {
  background: #bbb;
  box-shadow: none;
  cursor: not-allowed;
}

/* ── SPINNER ── */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #ddd;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}

.spinner.is-active {
  display: inline-block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── HISTORY VIEW ── */
.history-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  background: #fff;
  border: 1px solid var(--line);
  padding: 16px 20px;
  margin-bottom: 24px;
}

.history-toolbar .field {
  flex: 1 1 240px;
  min-width: 0;
}

.history-toolbar button {
  padding: 10px 18px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-family: 'Jost', sans-serif;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-radius: var(--radius);
  transition:
    background 0.2s,
    border-color 0.2s;
  cursor: pointer;
  height: 38px;
}

.history-toolbar button:hover {
  border-color: var(--ink);
}

.history-toolbar button.primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.history-toolbar button.primary:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.history-results {
  display: grid;
  gap: 8px;
}

.history-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px 16px;
  padding: 14px 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: left;
  cursor: pointer;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
  font-family: inherit;
  color: inherit;
}

.history-item:hover {
  border-color: var(--ink);
  box-shadow: 0 4px 16px rgba(26, 26, 46, 0.08);
}

.history-item.is-active {
  border-color: var(--accent);
}

.history-item .id {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.history-item .meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.history-item .status {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--field-bg);
}

.history-empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.detail-card {
  background: #fff;
  border: 1px solid var(--line);
  padding: 20px 24px;
  margin-top: 24px;
  display: grid;
  gap: 16px;
}

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.detail-head h3 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
}

.detail-head .meta {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.detail-card pre {
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.5;
  background: #201d1a;
  color: #f7f2eb;
  padding: 16px;
  border-radius: var(--radius);
  overflow: auto;
  max-height: 320px;
  white-space: pre-wrap;
  word-break: break-word;
}

.detail-card .btn-regenerate {
  padding: 11px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  font-family: 'Jost', sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(139, 26, 26, 0.25);
  transition: background 0.2s;
}

.detail-card .btn-regenerate:hover {
  background: var(--accent-dark);
}

.detail-card .btn-regenerate:disabled {
  background: #bbb;
  box-shadow: none;
  cursor: not-allowed;
}

/* ── RESPONSIVE ── */
@media (max-width: 720px) {
  .header-inner {
    padding: 14px 16px;
    flex-wrap: wrap;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .main-content {
    padding: 24px 12px 100px;
  }

  .section-body {
    padding: 16px;
  }

  .fields-grid,
  .fields-grid.cols-3 {
    grid-template-columns: 1fr;
  }

  .generate-bar-inner {
    padding: 12px 16px;
  }

  #btn-generate {
    padding: 12px 20px;
    font-size: 12px;
  }
}
