:root {
  --bg: #f3eee4;
  --bg-2: #e4efe6;
  --card: #fffdf8;
  --field: #f6f0e4;
  --ink: #1c1915;
  --muted: #5e584f;
  --line: #e3d7c6;
  --accent: #1b5e4a;
  --accent-ink: #f7f3ea;
  --danger: #8f3d45;
  --shadow: 0 12px 32px rgba(70, 46, 22, 0.08);
  --serif: "Fraunces", "Iowan Old Style", Palatino, serif;
  --font: "Outfit", "Segoe UI", sans-serif;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #101412;
  --bg-2: #1a2822;
  --card: #1a221e;
  --field: #121815;
  --ink: #f4efe6;
  --muted: #c3b8a8;
  --line: #314038;
  --accent: #8fd0b8;
  --accent-ink: #10211a;
  --danger: #f0a8ae;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 0% -10%, var(--bg-2), transparent 55%),
    var(--bg);
}

button, input, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 75%, white);
  outline-offset: 2px;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 650; letter-spacing: -0.02em; }

.screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.login-card, .card, dialog {
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.login-card {
  width: min(440px, 100%);
  border-radius: 28px;
  padding: 22px 18px 16px;
}

.login-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }

.brand h1 { margin: 0; font-size: 1.55rem; line-height: 1.05; }

.brand p, .summary { margin: 3px 0 0; color: var(--muted); font-size: 0.92rem; }

.logo {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.wrap { width: min(560px, 100%); margin: 0 auto; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(14px + env(safe-area-inset-top)) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
}

.top-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.top-actions button,
.top-actions a {
  min-height: 44px;
  padding: 8px 10px;
  font-size: 14px;
}

.top-actions a {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  font: inherit;
  text-align: center;
  text-decoration: none;
}

a.ghost {
  border-radius: 14px;
  border: 1px solid var(--line);
}

@media (min-width: 480px) {
  .top-actions { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.toolbar { padding: 14px 16px 0; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.list-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
}

.list-tools input,
.list-tools select {
  width: 100%;
  min-width: 0;
  height: 48px;
  min-height: 48px;
  box-sizing: border-box;
  font: inherit;
  font-size: 16px;
  line-height: 1.2;
  border-radius: 14px;
  padding: 12px 14px;
}

.list-tools select {
  width: 11.5rem;
  max-width: 46vw;
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid transparent;
  font-weight: 700;
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--accent-ink) 50%),
    linear-gradient(135deg, var(--accent-ink) 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 2px), calc(100% - 12px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.section-title {
  margin: 18px 16px 8px;
  font-size: 1.15rem;
}

.cards {
  list-style: none;
  margin: 0;
  padding: 0 16px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  border-radius: 20px;
  border-left-width: 7px;
  padding: 14px 14px 12px;
}

.card[data-status="bekliyor"] { border-left-color: #c4842a; }
.card[data-status="teslim"] { border-left-color: #1f8a62; }
.card[data-status="iptal"] { border-left-color: #b5525c; }

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card h2 {
  margin: 0;
  font-size: 1.28rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.badge {
  flex: 0 0 auto;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 5px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge.bekliyor { background: #fff1d6; color: #8a5a10; }
.badge.teslim { background: #e5f6ee; color: #0f6b4c; }
.badge.iptal { background: #fdecee; color: #8f3d45; }

[data-theme="dark"] .badge.bekliyor { background: #3a2c16; color: #f0c27a; }
[data-theme="dark"] .badge.teslim { background: #143328; color: #9ee0c4; }
[data-theme="dark"] .badge.iptal { background: #3a1d22; color: #f3b4ba; }

.kicker {
  margin: 12px 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.meds {
  margin: 0 0 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.dates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}

.dates div {
  background: var(--field);
  border-radius: 14px;
  padding: 8px 10px;
}

.dates dt { color: var(--muted); font-size: 0.75rem; }
.dates dd { margin: 2px 0 0; font-weight: 700; }

.card-actions {
  display: grid;
  grid-template-columns: 1fr 0.72fr 1.2fr;
  gap: 8px;
  margin-top: 12px;
}

button.primary,
button.ghost,
button.danger,
button.danger-solid,
button.chip,
button.choice {
  border-radius: 14px;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid transparent;
}

.primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
a.primary {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  min-height: 46px;
  padding: 10px 12px;
  text-decoration: none;
}
.ghost { background: var(--card); color: var(--ink); border-color: var(--line); }
.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 55%, var(--line)); font-weight: 650; }
.danger-solid { background: #8f3d45; color: #fffdf8; font-weight: 700; }
.full { width: 100%; }
.icon-btn { width: auto; white-space: nowrap; }

.chip {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
  min-height: 40px;
  border-radius: 999px;
  padding: 8px 14px;
}

.chip.is-on { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; }

.card-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.15;
  white-space: normal;
}

label {
  display: block;
  margin: 12px 0 6px;
  font-size: 0.92rem;
  font-weight: 650;
}

input, textarea {
  width: 100%;
  font-size: 16px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}

textarea { min-height: 110px; resize: vertical; }

.form-error { min-height: 1.2em; margin: 8px 0; color: var(--danger); font-size: 0.92rem; }
.hint { margin: 0 0 4px; color: var(--muted); }
.empty {
  margin: 8px 16px 16px;
  padding: 22px 16px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  color: var(--muted);
  background: color-mix(in srgb, var(--card) 70%, transparent);
}
.footnote { margin: 14px 0 0; color: var(--muted); font-size: 0.85rem; text-align: center; }
.footnote.pad { margin: 4px 16px calc(20px + env(safe-area-inset-bottom)); }

dialog.sheet {
  border: none;
  padding: 0;
  color: var(--ink);
  width: min(480px, 100%);
  max-height: min(92dvh, 760px);
  border-radius: 24px;
}

dialog::backdrop { background: rgba(18, 16, 12, 0.5); }

.dialog-body { padding: 18px 16px 16px; overflow: auto; }
.dialog-body h3 { margin: 0 0 6px; font-size: 1.45rem; }

.dialog-actions { display: flex; gap: 8px; margin-top: 8px; }
.dialog-actions button { flex: 1; }

.status-actions { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }

.choice {
  text-align: left;
  background: var(--field);
  border-color: var(--line);
  color: var(--ink);
}

.choice strong, .choice span { display: block; }
.choice span { color: var(--muted); font-size: 0.85rem; font-weight: 500; margin-top: 2px; }

.js-theme { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.js-theme svg { width: 18px; height: 18px; flex: 0 0 auto; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 30;
  max-width: min(420px, calc(100% - 24px));
  padding: 12px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  text-align: center;
  box-shadow: var(--shadow);
}

@media (max-width: 640px) {
  dialog.sheet {
    position: fixed;
    inset: auto 0 0 0;
    margin: 0;
    width: 100%;
    max-width: 100%;
    border-radius: 22px 22px 0 0;
  }
}

@media (hover: hover) {
  .primary:hover, .danger-solid:hover, .chip.is-on:hover { filter: brightness(1.08); }
  .ghost:hover, .choice:hover, .chip:hover { background: var(--field); }
  .chip.is-on:hover { background: var(--accent); }
}

html[data-app="install"] #loginScreen,
html[data-app="install"] #appShell { display: none !important; }
html[data-app="install"] #installPanel { display: flex !important; }
html[data-app="ready"] #installPanel { display: none !important; }

.install-panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 12px calc(16px + env(safe-area-inset-bottom));
  background:
    radial-gradient(900px 420px at 0% -10%, var(--bg-2), transparent 55%),
    var(--bg);
}

.install-card {
  width: min(480px, 100%);
  max-height: min(92dvh, 720px);
  overflow: auto;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 18px 16px 14px;
  box-shadow: var(--shadow);
}

.install-card h2 { margin: 0 0 6px; font-size: 1.45rem; }

.install-steps {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.install-steps li { display: flex; gap: 10px; align-items: flex-start; }
.install-steps svg { width: 28px; height: 28px; flex: 0 0 auto; color: var(--accent); }
.install-actions { display: flex; gap: 8px; }
.install-actions button { flex: 1; }
#installNow { margin-bottom: 8px; }

.report-view {
  min-height: 100dvh;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  background: #fff;
  color: #1c1915;
}

.report-actions { display: flex; gap: 8px; margin-bottom: 16px; }
.report-actions button,
.report-actions a { flex: 1; text-align: center; }
.report-view h1 { margin: 0 0 4px; font-size: 1.6rem; color: #1c1915; }
.report-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.report-table th,
.report-table td {
  border-bottom: 1px solid #e3d7c6;
  text-align: left;
  vertical-align: top;
  padding: 10px 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.report-table th { font-size: 0.85rem; color: #5e584f; }
.report-table tr.delivered td {
  position: relative;
  text-decoration: line-through;
}
.report-table tr.delivered td::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  border-top: 2px solid currentColor;
  pointer-events: none;
}
.report-note {
  display: inline-block;
  margin-left: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 0.02em;
}

@media print {
  #installPanel, #loginScreen, #appShell, #toast { display: none !important; }
  #reportView:not([hidden]) { display: block !important; position: static; min-height: auto; padding: 0; }
  .report-actions { display: none !important; }
  .report-view h1, .report-view p, .report-table, .report-table th, .report-table td { color: #000; }
  .report-table tr.delivered td::after { border-top-color: #000; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
