:root {
  --teal: #4ba3b3;
  --teal-strong: #3a8d9c;
  --teal-ink: #2b6f7b;
  --teal-soft: #eaf5f7;
  --flash: rgba(75, 163, 179, 0.38);
  --ink: #1c2a30;
  --muted: #66777e;
  --faint: #a7b4b9;
  --line: #e0e7ea;
  --bg: #f4f7f8;
  --card: #ffffff;
  --field: #f6f9fa;
  --danger: #c0392b;
  --amber: #c27c0e;
  --live: #2a9d68;
  --warn-bg: #fff5e6;
  --warn-ink: #7a5000;
  --toast: #1c2a30;
  --other: #9aa9af;
  --shadow: 0 1px 2px rgba(16, 40, 48, 0.05), 0 6px 20px rgba(16, 40, 48, 0.06);
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --teal: #4ba3b3;
    --teal-strong: #2f7f8d;
    --teal-ink: #8fd3de;
    --teal-soft: #173238;
    --flash: rgba(75, 163, 179, 0.45);
    --ink: #e7eef0;
    --muted: #9badb3;
    --faint: #5c6d73;
    --line: #26363c;
    --bg: #0e181c;
    --card: #152328;
    --field: #0f1c20;
    --warn-bg: #3a2b10;
    --warn-ink: #f3d08c;
    --toast: #2a3c42;
    --other: #6f8187;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button { font: inherit; color: inherit; cursor: pointer; }

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px calc(32px + env(safe-area-inset-bottom));
}

/* ---------- Üst bölüm ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  margin: 0 -16px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
}

.top-row { display: flex; align-items: center; gap: 10px; }

.title { margin: 0; font-size: 21px; font-weight: 750; letter-spacing: -0.01em; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding: 4px 10px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.status.live i { background: var(--live); box-shadow: 0 0 0 0 rgba(42, 157, 104, 0.5); animation: pulse 2.4s infinite; }
.status.wait i, .status.test i { background: var(--amber); }
.status.off i { background: var(--danger); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(42, 157, 104, 0.45); }
  70% { box-shadow: 0 0 0 7px rgba(42, 157, 104, 0); }
  100% { box-shadow: 0 0 0 0 rgba(42, 157, 104, 0); }
}

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
}
.icon-btn:active { transform: scale(0.96); }

.week-nav {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.week-label { text-align: center; line-height: 1.25; }
.week-label strong { display: block; font-size: 17px; font-weight: 700; }

.link-btn {
  border: 0;
  background: none;
  padding: 2px 0;
  color: var(--teal-ink);
  font-size: 13px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.mobile-bar { margin-top: 12px; }
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
}
.seg button {
  border: 0;
  background: transparent;
  padding: 8px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 650;
  color: var(--muted);
}
.seg button[aria-selected="true"] { background: var(--teal); color: #fff; }

.days {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-top: 10px;
}
.days button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 7px 0 8px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
}
.days .dn { font-size: 12px; font-weight: 600; color: var(--muted); }
.days .dd { font-size: 18px; font-weight: 750; }
.days .count { margin-top: 1px; font-size: 12px; font-weight: 700; color: var(--teal-ink); line-height: 1.2; }
.days .count.zero { color: var(--faint); }
.days .is-today { border-color: var(--teal); }
.days .is-today .dd { color: var(--teal-ink); }
.days button[aria-selected="true"] { background: var(--teal); border-color: var(--teal); color: #fff; }
.days button[aria-selected="true"] .dn,
.days button[aria-selected="true"] .dd,
.days button[aria-selected="true"] .count { color: #fff; }

main { margin-top: 6px; }

/* ---------- Tablo (senin örneğinin düzeni) ---------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

.grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}
.grid th, .grid td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.grid tr > :last-child { border-right: 0; }
.grid tbody tr:last-child > * { border-bottom: 0; }

.grid thead th {
  background: var(--teal);
  color: #fff;
  text-align: left;
  font-size: 16px;
  font-weight: 700;
  padding: 12px;
  border-color: rgba(255, 255, 255, 0.2);
  vertical-align: bottom;
}
.grid thead th small { display: block; margin-top: 1px; font-size: 12px; font-weight: 500; opacity: 0.9; }
.grid thead th.is-today { background: var(--teal-strong); }

.grid th.t { width: 84px; }
.grid tbody th.t {
  background: var(--card);
  text-align: left;
  font-weight: 600;
  font-size: 15px;
  padding: 12px;
  font-variant-numeric: tabular-nums;
}
.grid tbody th.t .sep { display: none; }
.grid tbody th.t .t2 { display: block; color: var(--muted); font-weight: 500; font-size: 13px; }

.grid td { padding: 0; vertical-align: top; }

.cell { display: flex; flex-direction: column; gap: 6px; min-height: 92px; padding: 8px; }

.item {
  border: 1px solid var(--line);
  border-left: 3px solid var(--other);
  border-radius: 10px;
  background: var(--card);
  overflow: hidden;
}
.item.mine { border-left-color: var(--teal); }
.item.flash { animation: flash 1.8s ease-out; }
@keyframes flash { from { background: var(--flash); } to { background: var(--card); } }
.item-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  background: transparent;
  text-align: left;
  font-size: 15px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.item-main:active { background: var(--teal-soft); }
.item-main:focus-visible, .add:focus-visible, .v-drive:focus-visible { outline: 2px solid var(--teal); outline-offset: -2px; border-radius: 8px; }
@media (hover: hover) { .item-main:hover { background: var(--teal-soft); } }
.v-title { font-weight: 700; }
.v-by { font-size: 12px; font-weight: 600; color: var(--muted); }
.v-drive {
  display: block;
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  color: var(--teal-ink);
  font-size: 13px;
  font-weight: 650;
}

.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.4;
  background: var(--chip-bg, var(--teal-soft));
  color: var(--chip-ink, var(--teal-ink));
}
.p0 { --chip-bg: #e3f2f5; --chip-ink: #1f5f6b; }
.p1 { --chip-bg: #ece9fb; --chip-ink: #4a3d99; }
.p2 { --chip-bg: #fde9df; --chip-ink: #8c3a14; }
.p3 { --chip-bg: #e4f3e3; --chip-ink: #2c6330; }
.p4 { --chip-bg: #fbe6ef; --chip-ink: #8a2754; }
.p5 { --chip-bg: #fbf0d4; --chip-ink: #6f4f06; }
@media (prefers-color-scheme: dark) {
  .p0 { --chip-bg: #17363d; --chip-ink: #9adbe6; }
  .p1 { --chip-bg: #2b2650; --chip-ink: #c5bdfa; }
  .p2 { --chip-bg: #43240f; --chip-ink: #f7bd9c; }
  .p3 { --chip-bg: #1c3a1f; --chip-ink: #a9dba8; }
  .p4 { --chip-bg: #42182c; --chip-ink: #f3b0cd; }
  .p5 { --chip-bg: #3a2d0b; --chip-ink: #ecd08a; }
}

.add {
  margin-top: auto;
  min-height: 40px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.add b { font-size: 16px; line-height: 1; }
.cell.empty .add { flex: 1; }
@media (hover: hover) { .add:hover { background: var(--teal-soft); color: var(--teal-ink); border-color: var(--teal); } }

/* Haftalık tablo telefonda yana kayar; saat sütunu sabit kalır. */
.week-view .table-wrap { scroll-snap-type: x proximity; scroll-padding-left: 84px; }
.week-view .grid thead th:not(.t) { scroll-snap-align: start; }
.week-view .grid { min-width: calc(84px + var(--gun, 5) * 168px); }
.week-view .grid th.t {
  position: sticky;
  left: 0;
  z-index: 1;
  box-shadow: 1px 0 0 var(--line);
}
.week-view .grid thead th.t { background: var(--teal); }

@media (max-width: 759px) {
  body[data-view="day"] .week-view { display: none; }
  body[data-view="week"] .day-view,
  body[data-view="week"] .days { display: none; }
}

/* ---------- Geniş ekran: örnekteki tablonun birebir hâli ---------- */
@media (min-width: 760px) {
  .app { padding: 0 28px 40px; }
  .top { margin: 0 -28px; padding: 22px 28px 14px; }
  .top-row { gap: 14px; }
  .title { font-size: 26px; }
  .status { margin-left: 0; }
  #share { margin-left: auto; }
  .week-nav { grid-template-columns: 42px auto 42px; justify-content: start; gap: 14px; margin-top: 14px; }
  .week-label { text-align: left; min-width: 260px; }
  .week-label strong { font-size: 18px; }
  .mobile-bar, .days, .day-view { display: none; }
  main { margin-top: 10px; }
  .week-view .grid { min-width: 0; }
  .grid th.t { width: 150px; }
  .grid thead th { font-size: 20px; padding: 18px 14px 14px; }
  .grid tbody th.t { font-size: 16px; font-weight: 500; padding: 14px; vertical-align: middle; }
  .grid tbody th.t .sep { display: inline; }
  .grid tbody th.t .t2 { display: inline; color: inherit; font-size: inherit; font-weight: inherit; }
  .cell { min-height: 112px; }
}

/* ---------- Yönetici, ipucu, isim ekranı ---------- */
.badge {
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--teal-soft);
  color: var(--teal-ink);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
@media (max-width: 759px) {
  .title { font-size: 20px; white-space: nowrap; }
  .status { margin-left: 0; }
  #share { margin-left: auto; }
  /* Telefonda yer dar: etiket yerine kalkan simgesi (metin ekran okuyucu için kalır). */
  .top-row .badge {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    padding: 0;
    font-size: 0;
  }
  .top-row .badge[hidden] { display: none; }
  .top-row .badge::before {
    content: "";
    width: 15px;
    height: 15px;
    background: var(--teal-ink);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2 4 5v6c0 5 3.4 9.7 8 11 4.6-1.3 8-6 8-11V5l-8-3zm-1.2 14.2-3.5-3.5 1.4-1.4 2.1 2.1 4.9-4.9 1.4 1.4-6.3 6.3z'/%3E%3C/svg%3E") center / contain no-repeat;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2 4 5v6c0 5 3.4 9.7 8 11 4.6-1.3 8-6 8-11V5l-8-3zm-1.2 14.2-3.5-3.5 1.4-1.4 2.1 2.1 4.9-4.9 1.4 1.4-6.3 6.3z'/%3E%3C/svg%3E") center / contain no-repeat;
  }
}

.hint { margin: 12px 4px 0; font-size: 13px; color: var(--muted); line-height: 1.45; }
.hint:empty { display: none; }
.hint .link-btn { font-size: 13px; margin-left: 6px; }
.welcome { position: fixed; inset: 0; z-index: 70; background: var(--bg); overflow-y: auto; }
.welcome .landing-card { width: 100%; text-align: left; }
.welcome .landing-card img, .welcome h1, .welcome .landing-card > p { text-align: center; }
.welcome .landing-card img { display: block; margin: 0 auto; }
.welcome .landing-card > p { margin-bottom: 18px; }
.welcome input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}
.welcome input:focus { outline: 2px solid var(--teal); outline-offset: -1px; background: var(--card); }
.btn.wide { width: 100%; margin-top: 4px; }
.welcome .link-btn { display: block; margin: 12px auto 0; }
.welcome-error { margin: 0 0 12px; color: var(--danger); font-size: 14px; font-weight: 600; }
.welcome .welcome-note { margin: 16px 0 0; font-size: 13px; color: var(--muted); }

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

/* ---------- Karşılama ---------- */
.landing {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.landing-card {
  max-width: 380px;
  padding: 32px 24px;
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
  text-align: center;
}
.landing-card img { border-radius: 16px; }
.landing-card h1 { margin: 14px 0 8px; font-size: 22px; }
.landing-card p { margin: 0 0 20px; color: var(--muted); }

/* ---------- Düğmeler ---------- */
.btn {
  height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 16px;
  font-weight: 650;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.danger { color: var(--danger); border-color: transparent; background: transparent; padding: 0 8px; }

/* ---------- Düzenleme penceresi ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(8, 22, 27, 0);
  transition: background 0.2s;
}
.sheet-backdrop.open { background: rgba(8, 22, 27, 0.42); }

.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0;
  background: var(--card);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.12);
  transform: translateY(100%);
  transition: transform 0.22s ease;
}
.sheet-backdrop.open .sheet { transform: none; }

.grip { width: 40px; height: 5px; margin: 0 auto 12px; border-radius: 9px; background: var(--line); }
.sheet h2 { margin: 0; font-size: 19px; font-weight: 750; }
.sheet-date { margin: 2px 0 14px; color: var(--muted); font-size: 14px; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; margin-bottom: 5px; font-size: 13px; font-weight: 650; color: var(--muted); }

.sheet input, .sheet textarea, .sheet select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* iPhone'da yakınlaştırmayı önler */
}
.sheet textarea { min-height: 70px; resize: vertical; }
.sheet input:focus, .sheet textarea:focus, .sheet select:focus { outline: 2px solid var(--teal); outline-offset: -1px; background: var(--card); }

.sheet-meta { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.sheet-meta:empty { display: none; }

.sheet-warn {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 14px;
}
.sheet-warn .link-btn { color: inherit; margin-left: 4px; }


.actions { display: flex; gap: 8px; }
.actions .primary { flex: 1; }
.actions #btn-delete { margin-right: auto; }

.field em { font-style: normal; font-weight: 500; }
.field small { display: block; margin-top: 5px; font-size: 13px; line-height: 1.4; color: var(--muted); }
.sheet select { appearance: none; -webkit-appearance: none; height: 49px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237f9198' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 18px; padding-right: 40px; }
.btn.drive {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-color: var(--teal);
  color: var(--teal-ink);
  text-decoration: none;
}
.btn.drive.off { border-color: var(--line); color: var(--faint); cursor: not-allowed; }
.read-title { margin: 0 0 10px; font-size: 18px; font-weight: 700; line-height: 1.35; overflow-wrap: anywhere; }
#sheet-read .btn.drive { margin-top: 16px; }
#sheet-read { margin-bottom: 16px; }

@media (min-width: 760px) {
  .sheet-backdrop { align-items: center; padding: 24px; }
  .sheet { border-radius: 22px; padding-bottom: 20px; transform: translateY(16px); opacity: 0; transition: transform 0.2s ease, opacity 0.2s ease; }
  .sheet-backdrop.open .sheet { opacity: 1; }
  .grip { display: none; }
}

/* ---------- Bildirim ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--toast);
  color: #fff;
  font-size: 15px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  transform: translate(-50%, 24px);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.25s ease, opacity 0.25s ease, visibility 0.25s;
  pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; pointer-events: auto; }
.toast button { border: 0; background: none; padding: 0; color: #8fdbe7; font-weight: 750; white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
