/* Patch — styles. Notes-app feel: quiet, typographic, keyboard-visible focus. */

:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --ink: #23231f;
  --muted: #7d7a70;
  --line: #e4e1d8;
  --accent: #1f6f5c;
  --accent-soft: #e3efeb;
  --star: #b8860b;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --red: #b91c1c;
  --red-bg: #fee2e2;
  --blue: #1d4ed8;
  --blue-bg: #dbeafe;
  --done: #9a978d;
  --focus: #1f6f5c;
  --shadow: 0 1px 3px rgba(0,0,0,.07);
  --focus-bg: #fbfefd;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191a17;
    --panel: #232420;
    --ink: #e8e6df;
    --muted: #96938a;
    --line: #38393300;
    --line: #383933;
    --accent: #4fa88f;
    --accent-soft: #223730;
    --star: #d9a521;
    --amber: #f59e0b;
    --amber-bg: #3a2c10;
    --red: #f87171;
    --red-bg: #3c1a1a;
    --blue: #93b4f5;
    --blue-bg: #1d2b4a;
    --done: #6f6d64;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
    --focus-bg: #26302c;
  }
}

* { box-sizing: border-box; }
* { touch-action: manipulation; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: 40vh;
}
.hidden { display: none !important; }
.spacer { flex: 1; }
button {
  font: inherit; color: inherit; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 4px 10px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: transparent; }
button.danger { color: var(--red); }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, [tabindex]:focus-visible, summary:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 8px;
}
input, textarea, select {
  font: inherit; color: inherit; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px;
}
textarea { resize: vertical; }
hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; }

/* ---------- top bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--bg); border-bottom: 1px solid var(--line);
  padding: 8px 14px 6px;
}
.bar-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 2px 0; }
#brand { font-size: 17px; white-space: nowrap; }
#search { flex: 1; min-width: 160px; max-width: 460px; }
#sync-status {
  font-size: 12px; color: var(--muted); white-space: nowrap;
  background: transparent; border-color: transparent;
}
#sync-status:hover { border-color: var(--line); }
#sync-status.warn { color: var(--amber); border-color: var(--amber); font-weight: 600; }
.badge {
  background: var(--red); color: #fff; border-radius: 9px;
  font-size: 11px; padding: 0 5px; margin-left: 3px; vertical-align: top;
}

.dropdown { position: relative; }
.dropdown > summary {
  list-style: none; cursor: pointer; user-select: none;
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 8px; padding: 4px 10px;
}
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown-body {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 50;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,.18);
  min-width: 230px; padding: 6px; display: flex; flex-direction: column; gap: 2px;
}
.dropdown-body button { border: none; background: none; text-align: left; padding: 7px 10px; border-radius: 7px; }
.dropdown-body button:hover { background: var(--accent-soft); }

#chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border-radius: 999px; padding: 3px 11px; font-size: 13px;
  background: var(--panel); border: 1px solid var(--line);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .cnt { opacity: .65; font-size: 11px; margin-left: 3px; }
.ctl { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.ctl select { padding: 3px 6px; font-size: 13px; }
.ctl-btn { font-size: 13px; }
.ctl-btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; border-radius: 0; font-size: 13px; padding: 4px 10px; background: var(--panel); }
.seg button.on { background: var(--accent); color: #fff; }

#notif-banner {
  margin: 10px 14px 0; padding: 9px 14px; border-radius: 10px;
  background: var(--accent-soft); border: 1px solid var(--accent);
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 14px;
}

/* ---------- layout ---------- */
#layout { display: grid; grid-template-columns: 190px 1fr; gap: 18px; padding: 14px; max-width: 1200px; margin: 0 auto; }
/* Grid children default to min-width:auto and refuse to shrink below their content,
   which lets the horizontally-scrolling section row stretch the whole page wide. */
#sidebar, #main { min-width: 0; }
#sidebar { position: sticky; top: 92px; align-self: start; display: flex; flex-direction: column; gap: 6px; }
#sections { display: flex; flex-direction: column; gap: 3px; }
.secitem {
  text-align: left; border: none; background: none; padding: 6px 10px; border-radius: 8px;
  display: flex; justify-content: space-between; gap: 8px; font-size: 14px;
}
.secitem:hover { background: var(--accent-soft); }
.secitem.on { background: var(--accent); color: #fff; font-weight: 600; }
.secitem .cnt { opacity: .6; font-size: 12px; }
.secitem.dragover { outline: 2px dashed var(--accent); }
#add-section { border: 1px dashed var(--line); background: none; color: var(--muted); font-size: 13px; }

/* ---------- patch box ---------- */
#patchbox { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); }
#paste { width: 100%; border: none; padding: 4px 2px; background: none; font-size: 15px; }
#paste:focus-visible { outline: none; }
.patch-actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.mini { font-size: 12.5px; color: var(--muted); display: flex; gap: 5px; align-items: center; }
#drafts { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
#drafts .drafts-note { font-size: 13px; color: var(--muted); }
.draft {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 10px; padding: 5px 7px;
}
.draft-files { width: 100%; display: flex; gap: 6px; flex-wrap: wrap; }
.draft-file {
  font-size: 12px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 8px; display: inline-flex; gap: 6px; align-items: center;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.draft-file button { border: none; background: none; padding: 0; color: var(--muted); }
.draft .chip-text { flex: 1; background: var(--panel); resize: none; min-width: 120px; }
.chip-due {
  font-size: 11px; font-weight: 600; white-space: nowrap;
  background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 2px 8px;
}
.draft .chip-sec { font-size: 13px; }
.draft .chip-star { padding: 4px 7px; filter: grayscale(1); opacity: .5; }
.draft .chip-star.on { filter: none; opacity: 1; border-color: var(--star); }

/* ---------- list & cards ---------- */
#list { display: flex; flex-direction: column; gap: 20px; margin-top: 18px; }
.group h2 {
  font-size: 13.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 0 0 8px 4px; font-weight: 700;
}
.group h2 .gcount { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 0 7px; font-size: 11.5px; margin-left: 4px; }
.group { display: flex; flex-direction: column; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow);
  transition: transform .15s ease, opacity .2s ease;
}
/* The highlighted task — arrow keys move this, and every letter shortcut acts on it. */
.card:focus,
.card:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--accent), var(--shadow);
  background: var(--focus-bg);
}
.card:focus .num { color: var(--accent); font-weight: 700; }
.card.imp { border-left: 3px solid var(--star); }
/* Ignored-too-long tasks: red glowing border, pinned in the "Needs attention" block. */
.group-alert h2 { color: var(--red); display: flex; align-items: center; gap: 8px; }
.noticed-all { font-size: 12px; padding: 2px 10px; text-transform: none; letter-spacing: 0; font-weight: 600; }
.card.alerted { border-color: var(--red); animation: alert-glow 1.6s ease-in-out infinite; }
@keyframes alert-glow {
  0%, 100% { box-shadow: 0 0 4px 1px rgba(220, 38, 38, .35), var(--shadow); }
  50%      { box-shadow: 0 0 15px 4px rgba(220, 38, 38, .75), var(--shadow); }
}
.card.alerted:focus, .card.alerted:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.card.st-done { opacity: .62; }
.card.st-done .t-en, .card.st-done .t-he { text-decoration: line-through; color: var(--done); }
.card.st-ordered { border-left: 3px solid var(--blue); }
.card.dragover-top { box-shadow: 0 -3px 0 var(--accent), var(--shadow); }
.card.dragover-bottom { box-shadow: 0 3px 0 var(--accent), var(--shadow); }

.row1 { display: flex; gap: 9px; align-items: flex-start; }
.num { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; padding-top: 2px; white-space: nowrap; }
.texts { flex: 1; min-width: 0; }
.t-en { overflow-wrap: break-word; white-space: pre-wrap; }
.t-he { overflow-wrap: break-word; white-space: pre-wrap; text-align: right; color: var(--ink); opacity: .88; font-size: 14.5px; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; max-width: 260px; }
.tag {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  border-radius: 5px; padding: 2px 7px; white-space: nowrap;
  border: 1px solid var(--line); background: var(--bg); color: var(--muted);
}
.tag.imp { color: var(--star); border-color: var(--star); }
.tag.new { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.tag.send { color: var(--amber); border-color: var(--amber); }

.metaline { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-top: 7px; font-size: 12.5px; color: var(--muted); }
.pill { border-radius: 999px; padding: 1px 9px; font-size: 11.5px; font-weight: 600; background: var(--bg); border: 1px solid var(--line); }
.pill.st-open { }
.pill.st-in_progress { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.pill.st-waiting { background: var(--amber-bg); color: var(--amber); border-color: var(--amber); }
.pill.st-ordered { background: var(--blue-bg); color: var(--blue); border-color: var(--blue); }
.pill.st-done { background: var(--bg); color: var(--done); }
.mchip { border-radius: 6px; padding: 1px 7px; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.mchip.warn { background: var(--amber-bg); color: var(--amber); border-color: var(--amber); font-weight: 600; }
.mchip.bad { background: var(--red-bg); color: var(--red); border-color: var(--red); font-weight: 600; }
.mchip.good { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.t-open {
  font-variant-numeric: tabular-nums; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); border-radius: 6px; padding: 1px 8px; white-space: nowrap;
}
.t-open.done { color: var(--done); background: var(--bg); font-weight: 500; }
.mchip.sec { font-weight: 600; }

.actions { display: flex; gap: 6px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.actions button { font-size: 12.5px; padding: 3px 9px; }
.actions button.on { border-color: var(--amber); color: var(--amber); font-weight: 600; }
.actions kbd { font-size: 10.5px; padding: 0 4px; border-bottom-width: 1px; opacity: .75; margin-left: 2px; }
.act-sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 3px; }
.actions .warn { border-color: var(--amber); color: var(--amber); font-weight: 600; }
.cardmenu { position: relative; margin-left: auto; }
.cardmenu > summary { list-style: none; cursor: pointer; border: 1px solid var(--line); border-radius: 8px; padding: 2px 10px; background: var(--panel); }
.cardmenu > summary::-webkit-details-marker { display: none; }
.menu-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 5px 10px 1px; }
.statusrow { display: flex; gap: 4px; padding: 2px 8px 6px; flex-wrap: wrap; }
.statusrow button { font-size: 11.5px; padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); }
.statusrow button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* attachments strip */
.attstrip { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.att { position: relative; display: flex; flex-direction: column; gap: 2px; font-size: 11.5px; color: var(--muted); max-width: 180px; }
.att img { max-height: 74px; max-width: 120px; border-radius: 8px; border: 1px solid var(--line); object-fit: cover; cursor: zoom-in; }
.att audio { height: 34px; max-width: 220px; }
.att a { color: var(--accent); text-decoration: none; border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; background: var(--bg); display: inline-block; }
.att .att-del {
  position: absolute; top: -7px; right: -7px; z-index: 2;
  border-radius: 50%; width: 20px; height: 20px; padding: 0; font-size: 11px; line-height: 1;
  background: var(--panel);
}
.att .att-meta { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- edit mode ---------- */
.card.editing { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft), var(--shadow); }
.edit-head { display: flex; gap: 9px; align-items: center; margin-bottom: 8px; color: var(--muted); font-size: 13px; }
.edit-form { display: flex; flex-direction: column; gap: 8px; }
.edit-form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.edit-form textarea, .edit-form input, .edit-form select { font-size: 14.5px; }
.edit-form textarea[data-field="he"] { text-align: right; }
.fgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.due-hint { font-size: 11.5px; color: var(--accent); min-height: 14px; }
.due-hint.err { color: var(--red); }
.edit-actions { display: flex; gap: 8px; align-items: center; margin-top: 2px; }
.edit-actions .star { filter: grayscale(1); opacity: .55; }
.edit-actions .star.on { filter: none; opacity: 1; border-color: var(--star); color: var(--star); font-weight: 600; }
.notes-block { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.notes-block ul { list-style: none; margin: 0 0 6px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.notes-block li { font-size: 13px; }
.notes-block li .nat { color: var(--muted); font-size: 11.5px; margin-right: 7px; font-variant-numeric: tabular-nums; }
.note-input { width: 100%; font-size: 13.5px; }
.attach-block { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.attach-btns { display: flex; gap: 8px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.rec-on { background: var(--red) !important; border-color: var(--red) !important; color: #fff !important; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.empty { color: var(--muted); text-align: center; padding: 40px 0; font-size: 15px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 80;
  background: var(--ink); color: var(--bg); border-radius: 10px; padding: 10px 16px;
  box-shadow: 0 8px 30px rgba(0,0,0,.3); font-size: 14px; display: flex; gap: 12px; align-items: center;
  max-width: min(92vw, 560px);
}
#toast button { background: none; border: none; color: var(--star); font-weight: 700; padding: 0; }

/* ---------- modal ---------- */
#modal {
  position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.42);
  display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px;
}
#modal-card {
  background: var(--bg); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.4);
  max-width: 860px; width: 100%; max-height: 88vh; overflow: auto; padding: 20px; position: relative;
}
#modal-close { position: absolute; top: 12px; right: 12px; }
#modal-body h2 { margin: 4px 0 12px; font-size: 19px; }
#modal-body h3 { margin: 18px 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
#modal-body table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
#modal-body th, #modal-body td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
#modal-body th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.dash-row { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; align-items: baseline; }
.dash-row .who { color: var(--muted); font-size: 12px; }
.bar { height: 8px; background: var(--accent); border-radius: 4px; min-width: 2px; }
.bar-row2 { display: grid; grid-template-columns: 120px 1fr 76px; gap: 8px; align-items: center; font-size: 13px; padding: 3px 0; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.settings-grid label, .settings-full label { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--muted); }
.settings-full { margin-bottom: 10px; }
kbd {
  background: var(--panel); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 6px; padding: 1px 7px; font-size: 12.5px; font-family: inherit;
}

/* bell */
#bell-body { max-width: 340px; min-width: 300px; max-height: 60vh; overflow: auto; }
.bell-item { padding: 7px 9px; border-radius: 8px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.bell-item:hover { background: var(--accent-soft); }
.bell-item .b-title { font-weight: 600; }
.bell-item .b-kind { font-size: 11.5px; }
.bell-item .b-kind.bad { color: var(--red); }
.bell-item .b-kind.warn { color: var(--amber); }
.bell-acts { display: flex; gap: 5px; flex-wrap: wrap; }
.bell-acts button { font-size: 11.5px; padding: 2px 8px; }
.bell-empty { padding: 14px; color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- phone layout ---------- */
/* Same DOM, different presentation: .pc-act shows only on desktop,
   .mob-act / .mob-menu only on phones. */
.mob-act, .mob-menu { display: none; }

@media (max-width: 760px) {
  /* iOS auto-zooms into any focused field under 16px, and more specific
     desktop rules (.edit-form, .ctl select…) set 13–14.5px — the !important
     is deliberate: nothing may undercut 16px on a phone. */
  body { font-size: 16px; }
  input, textarea, select { font-size: 16px !important; }

  #layout { grid-template-columns: 1fr; gap: 8px; padding: 8px; }
  #sidebar { position: static; }
  #sections { flex-direction: row; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .secitem { white-space: nowrap; border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; flex: 0 0 auto; }
  #add-section { display: none; }

  /* top bar: slim scrollable rows instead of a four-line wrap */
  #topbar { padding: 6px 8px 4px; }
  #controls { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 6px; padding-bottom: 4px; }
  #controls .spacer { display: none; }
  #chips { flex-wrap: nowrap; }
  .chip, .ctl, .ctl-btn { white-space: nowrap; flex: 0 0 auto; }
  .chip { padding: 6px 13px; }
  .seg button { padding: 6px 12px; }
  #search { min-width: 100px; }
  #sync-status { display: none; }   /* tiny screens: trust the save, drop the label */

  /* cards: only Done / Sent / Edit / Dismiss / More — big enough for thumbs */
  .card { padding: 12px; }
  .pc-act { display: none !important; }
  .mob-act { display: inline-block; }
  .mob-menu { display: block; }
  .act-sep { display: none; }
  .actions { gap: 8px; }
  .actions button, .cardmenu > summary { padding: 8px 14px; font-size: 15px; border-radius: 10px; }
  .actions kbd, .dropdown-body kbd { display: none; }
  .metaline { font-size: 12px; gap: 5px 8px; }
  .badges { max-width: 42%; }
  .row1 { flex-wrap: wrap; }
  .num { font-size: 12px; }

  /* edit form + drafts */
  .fgrid { grid-template-columns: 1fr 1fr; }
  .edit-actions { flex-wrap: wrap; }
  .draft .chip-text { min-width: 100%; }
  .patch-actions { flex-wrap: wrap; }

  /* modals go full screen */
  #modal { padding: 0; }
  #modal-card { height: 100%; max-height: 100vh; border-radius: 0; padding: 16px; }

  /* card menus hug the right edge without overflowing */
  .cardmenu .dropdown-body { max-width: calc(100vw - 40px); }
}

/* ---------- print ---------- */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; font-size: 12px; color: #000; }
  #print-area h1 { font-size: 18px; margin-bottom: 2px; }
  #print-area .sub { color: #555; margin-bottom: 14px; }
  #print-area table { border-collapse: collapse; width: 100%; }
  #print-area th, #print-area td { border: 1px solid #999; padding: 5px 7px; text-align: left; }
  #print-area th { background: #eee; }
}
