/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg: #faf9f7;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-text-muted: #5c5c5c;
  --color-text-subtle: #8a8a8a;
  --color-accent: #c44f34;
  --color-accent-hover: #a83d26;
  --color-accent-light: #fef0ec;
  --color-border: #e0ddd8;
  --color-border-light: #eeebe6;
  --color-success: #2d7d46;
  --color-warning: #b85c1a;
  --color-danger: #c0392b;
  --color-danger-bg: #fef5f4;
  --color-info-bg: #f4f7fb;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --max-width: 960px;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Header === */
.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--color-text);
  font-weight: 700;
  font-size: 1.1rem;
}
.logo svg { color: var(--color-accent); flex-shrink: 0; }
.site-nav { display: flex; gap: 20px; }
.site-nav a {
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  transition: color 0.15s;
}
.site-nav a:hover { color: var(--color-text); }

/* === Main Layout === */
main { flex: 1; }
.section-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 32px 20px;
}

/* === Section 1: Add Purchase === */
.add-purchase-section {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
.add-purchase-section h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 4px;
}
.subtitle {
  color: var(--color-text-muted);
  margin-bottom: 24px;
  max-width: 600px;
}
.purchase-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.form-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.form-group {
  flex: 1;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
}
.form-group input,
.form-group select {
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.15s;
  width: 100%;
}
.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-light);
}
.form-row-options {
  align-items: center;
  gap: 24px;
}
.checkbox-group {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-width: auto;
}
.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--color-accent);
  flex-shrink: 0;
}
.checkbox-group label {
  font-weight: 400;
  cursor: pointer;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn-primary {
  background: var(--color-accent);
  color: #fff;
  align-self: flex-start;
}
.btn-primary:hover { background: var(--color-accent-hover); }
.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover { background: #f5f3f0; }
.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  padding: 8px 12px;
  font-weight: 500;
}
.btn-ghost:hover { color: var(--color-danger); }
.btn-sm {
  padding: 5px 10px;
  font-size: 0.8rem;
}

.form-feedback {
  margin-top: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
}
.form-feedback.success { background: #eaf7ee; color: var(--color-success); }
.form-feedback.error { background: var(--color-danger-bg); color: var(--color-danger); }

/* === Section 2: Tracker Table === */
.tracker-section { background: var(--color-bg); }
.tracker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}
.tracker-header h2 { font-size: 1.35rem; font-weight: 700; }
.tracker-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--color-text-muted);
}
.empty-icon { margin-bottom: 12px; color: var(--color-text-subtle); }
.empty-hint { font-size: 0.9rem; color: var(--color-text-subtle); margin-top: 6px; }

.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}
.purchase-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 700px;
}
.purchase-table th {
  text-align: left;
  padding: 12px 14px;
  background: #f9f8f6;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
}
.purchase-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: middle;
}
.purchase-table tbody tr:last-child td { border-bottom: none; }
.purchase-table tbody tr:hover { background: #fdfcfb; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-ok { background: #eaf7ee; color: var(--color-success); }
.badge-warning { background: #fef3e8; color: var(--color-warning); }
.badge-overdue { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-returned { background: #f0f0f0; color: var(--color-text-subtle); }

.returned-row { opacity: 0.55; }
.returned-row td { text-decoration: line-through; text-decoration-color: var(--color-text-subtle); }

.summary-bar {
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--color-info-bg);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* === Section 3: Policy Reference === */
.reference-section {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
}
.reference-section h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: 6px; }
.reference-intro { color: var(--color-text-muted); margin-bottom: 20px; max-width: 640px; }
.policy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.policy-card {
  background: #fdfcfb;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.policy-card h4 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 4px;
}
.policy-card .policy-days {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}
.policy-card .policy-note {
  font-size: 0.78rem;
  color: var(--color-text-subtle);
  margin-top: 4px;
}
.reference-note {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}

/* === Section 4: Support Content === */
.support-section { background: var(--color-bg); }
.support-section h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: 20px; }
.support-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.support-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius);
  padding: 18px;
}
.support-card h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.support-card p {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}
.caveats-box {
  background: #fefbf8;
  border: 1px solid #f0e0d0;
  border-radius: var(--radius);
  padding: 20px;
}
.caveats-box h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 10px;
}
.caveats-box ul {
  list-style: disc;
  padding-left: 20px;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* === Footer === */
.site-footer {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  margin-top: auto;
}
.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px;
  text-align: center;
  font-size: 0.82rem;
  color: var(--color-text-subtle);
}
.footer-inner a { color: var(--color-text-muted); text-decoration: underline; }
.footer-inner a:hover { color: var(--color-text); }
.footer-links { margin-top: 6px; }
.footer-version { margin-top: 4px; font-size: 0.75rem; }

/* === Print Styles === */
@media print {
  .site-header, .site-footer, .add-purchase-section, .tracker-actions, .support-section, .reference-section, .summary-bar, #clear-btn, #share-btn {
    display: none !important;
  }
  .tracker-section { background: #fff; }
  .table-wrapper { border: 1px solid #ccc; }
  .purchase-table { min-width: auto; }
  body { font-size: 12px; }
  .section-inner { padding: 0; }
}

/* === Responsive === */
@media (max-width: 640px) {
  .header-inner { padding: 0 14px; }
  .section-inner { padding: 24px 14px; }
  .form-row { flex-direction: column; gap: 12px; }
  .form-group { min-width: 100%; }
  .tracker-header { flex-direction: column; align-items: flex-start; }
  .tracker-actions { width: 100%; justify-content: flex-start; }
  .policy-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .support-grid { grid-template-columns: 1fr; }
  .purchase-table { font-size: 0.8rem; }
}



/* Factory-injected deployment helpers. The AI owns the site design above this block. */
.ad-unit {
  width: min(100%, 720px);
  min-height: 120px;
  margin: 24px auto;
  display: block;
}

.legal-page {
  width: min(900px, calc(100% - 32px));
  margin: 40px auto;
}

.factory-fallback-nav {
  width: min(900px, calc(100% - 32px));
  margin: 24px auto 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  font-size: 0.95rem;
}

.factory-fallback-nav a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}
