:root {
  --bg: oklch(20% 0.012 260);
  --surface: oklch(25% 0.015 260);
  --surface-2: oklch(29% 0.018 260);
  --line: oklch(34% 0.02 260);
  --text: oklch(95% 0.005 260);
  --muted: oklch(68% 0.015 260);
  --accent: oklch(72% 0.16 162);
  --accent-ink: oklch(22% 0.05 162);
  --danger: oklch(64% 0.2 25);
  --radius: 14px;
  --radius-sm: 9px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; }

/* ---------- Login ---------- */
.login {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(120% 100% at 50% 0%, oklch(26% 0.03 162 / 0.5), var(--bg));
}
.login-card {
  width: min(360px, 90vw); display: flex; flex-direction: column; gap: 14px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 32px 28px;
  box-shadow: 0 30px 80px -30px oklch(0% 0 0 / 0.7);
}
.login-title { margin: 0; font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; }
.login-title span { color: var(--accent); }
.login-sub { margin: 0 0 6px; color: var(--muted); font-size: 0.9rem; }
.login-card input, .login-card button { padding: 12px 14px; border-radius: var(--radius-sm); }
.login-card input { background: var(--surface-2); border: 1px solid var(--line); color: var(--text); }
.login-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.login-card button { background: var(--accent); color: var(--accent-ink); border: 0; font-weight: 650; }
.login-card button:hover { filter: brightness(1.06); }
.login-error { margin: 0; color: var(--danger); font-size: 0.85rem; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 340px 1fr; height: 100vh; }

.sidebar { display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--line); min-height: 0; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 12px; }
.brand { font-size: 1.05rem; letter-spacing: -0.01em; }
.brand b { color: var(--accent); font-weight: 700; }
.status { font-size: 0.72rem; padding: 4px 9px; border-radius: 999px; font-weight: 600; }
.status--on { background: oklch(72% 0.16 162 / 0.16); color: var(--accent); }
.status--off { background: oklch(64% 0.2 25 / 0.16); color: var(--danger); }

.filters { padding: 4px 14px 12px; display: flex; flex-direction: column; gap: 10px; }
.filters input { width: 100%; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line); color: var(--text); }
.filters input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.filter-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tab { padding: 7px 8px; border-radius: var(--radius-sm); background: transparent; border: 1px solid var(--line); color: var(--muted); font-size: 0.8rem; font-weight: 600; transition: 0.15s var(--ease); white-space: nowrap; }
.tab.is-active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.tab b { font-weight: 700; opacity: 0.65; font-size: 0.72rem; margin-left: 2px; }
.tab-wait { width: 100%; text-align: center; padding: 9px; border-color: oklch(64% 0.2 25 / 0.5); color: oklch(72% 0.18 25); }
.tab-wait.is-active { background: oklch(64% 0.2 25); color: oklch(20% 0.04 25); border-color: transparent; }
.overdue-badge { font-size: 0.6rem; font-weight: 800; color: oklch(20% 0.04 25); background: var(--danger); padding: 2px 5px; border-radius: 5px; letter-spacing: 0.02em; }
.group.is-overdue { box-shadow: inset 3px 0 0 var(--danger); }
.group.is-overdue.is-active { box-shadow: inset 3px 0 0 var(--accent); }

.group-list { list-style: none; margin: 0; padding: 4px 8px 16px; overflow-y: auto; flex: 1; min-height: 0; }
.group {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 11px; align-items: center;
  padding: 10px 10px; border-radius: var(--radius-sm); cursor: pointer; transition: background 0.12s var(--ease);
}
.group:hover { background: var(--surface-2); }
.group.is-active { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 0.85rem; background: linear-gradient(150deg, var(--surface-2), var(--line)); color: var(--text); }
.group-mid { min-width: 0; }
.group-name { font-size: 0.9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group-last { font-size: 0.78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.group-right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.group-time { font-size: 0.68rem; color: var(--muted); }
.badges { display: flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px oklch(72% 0.16 162 / 0.18); }
.draft-badge { font-size: 0.72rem; color: var(--accent); font-weight: 700; }

/* ---------- Main ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }
.empty { flex: 1; display: grid; place-items: center; color: var(--muted); }
.thread { display: flex; flex-direction: column; height: 100vh; min-height: 0; }
.thread-head { padding: 16px 22px; border-bottom: 1px solid var(--line); background: var(--surface); }
.thread-head h2 { margin: 0; font-size: 1.05rem; letter-spacing: -0.01em; }
.thread-meta { font-size: 0.76rem; color: var(--muted); }

.messages { flex: 1; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 9px; min-height: 0; }
.msg { max-width: 68%; padding: 9px 13px; border-radius: 16px; font-size: 0.9rem; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap; }
.msg .who { display: block; font-size: 0.72rem; font-weight: 700; color: var(--accent); margin-bottom: 3px; }
.msg .time { display: block; font-size: 0.64rem; color: var(--muted); margin-top: 5px; text-align: right; }
.msg img { max-width: 240px; border-radius: 10px; margin-top: 4px; display: block; cursor: zoom-in; }
.msg--them { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg--me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 5px; }
.msg--me .who { color: var(--accent-ink); opacity: 0.7; }
.msg--me .time { color: var(--accent-ink); opacity: 0.6; }

.composer { border-top: 1px solid var(--line); padding: 12px 18px 16px; background: var(--surface); }
.composer-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; }
.bubble-toggle { display: inline-flex; align-items: center; gap: 7px; font-size: 0.78rem; color: var(--muted); cursor: pointer; }
.draft-btn { padding: 6px 13px; border-radius: 999px; background: transparent; border: 1px solid var(--accent); color: var(--accent); font-size: 0.78rem; font-weight: 650; transition: 0.15s var(--ease); }
.draft-btn:hover { background: oklch(72% 0.16 162 / 0.12); }
.draft-btn:disabled { opacity: 0.5; cursor: default; }
.composer-row { display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; padding: 11px 13px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line); color: var(--text); max-height: 160px; }
.composer textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.composer button { padding: 11px 22px; border-radius: var(--radius-sm); background: var(--accent); color: var(--accent-ink); border: 0; font-weight: 650; align-self: stretch; transition: 0.15s var(--ease); }
.composer button:hover { filter: brightness(1.06); }
.composer button:disabled { opacity: 0.5; cursor: default; }
.send-status { margin: 8px 0 0; font-size: 0.78rem; min-height: 1em; color: var(--muted); }
.send-status.err { color: var(--danger); }
.send-status.ok { color: var(--accent); }

/* Günaydın button + modal */
.morning-btn { margin: 0 14px 12px; padding: 11px; border-radius: var(--radius-sm); background: oklch(72% 0.16 162 / 0.12); border: 1px solid var(--accent); color: var(--accent); font-weight: 650; font-size: 0.88rem; transition: 0.15s var(--ease); }
.morning-btn:hover { background: oklch(72% 0.16 162 / 0.2); }

.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: oklch(0% 0 0 / 0.6); padding: 20px; }
.modal-card { width: min(520px, 96vw); max-height: 86vh; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 30px 80px -30px oklch(0% 0 0 / 0.7); overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal-close { background: transparent; border: 0; color: var(--muted); font-size: 1.1rem; }
.modal-close:hover { color: var(--text); }
.modal-tools { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.check-all { display: inline-flex; align-items: center; gap: 8px; font-size: 0.86rem; cursor: pointer; }
.modal-count { font-size: 0.78rem; color: var(--accent); font-weight: 600; }
.morning-list { list-style: none; margin: 0; padding: 8px 12px; overflow-y: auto; flex: 1; }
.morning-item label { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: 0.88rem; }
.morning-item label:hover { background: var(--surface-2); }
.morning-item input { width: 16px; height: 16px; accent-color: var(--accent); }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.morning-progress { margin: 0; font-size: 0.82rem; color: var(--muted); min-height: 1em; }
.morning-send { padding: 12px; border-radius: var(--radius-sm); background: var(--accent); color: var(--accent-ink); border: 0; font-weight: 650; transition: 0.15s var(--ease); }
.morning-send:hover { filter: brightness(1.06); }
.morning-send:disabled { opacity: 0.55; cursor: default; }

/* image lightbox */
.lightbox { position: fixed; inset: 0; background: oklch(0% 0 0 / 0.85); display: grid; place-items: center; z-index: 50; cursor: zoom-out; }
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 10px; }

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .app.thread-open .sidebar { display: none; }
  .app:not(.thread-open) .main { display: none; }
  .msg { max-width: 85%; }
}
