:root {
  --bg: #e4e7ee;
  --paper: #fffefb;
  --ink: #1b1b1f;
  --muted: #6b6f7b;
  --accent: #2f5bea;
  --line: #d6dcec;
  --dot: #b8c1d8;
  --bar-bg: #ffffff;
  --praca: #2f5bea;
  --firma: #c2410c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

#app { position: fixed; inset: 0; background: var(--bg); }

.view { position: absolute; inset: 0; display: flex; flex-direction: column; }
.view[hidden] { display: none; }

/* ---------- top bar ---------- */
.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  padding-top: calc(6px + env(safe-area-inset-top));
  padding-left: calc(10px + env(safe-area-inset-left));
  padding-right: calc(10px + env(safe-area-inset-right));
  background: var(--bar-bg);
  box-shadow: 0 1px 0 rgba(0,0,0,.08), 0 2px 8px rgba(0,0,0,.04);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  z-index: 2;
  overflow-x: auto;
  white-space: nowrap;
}
.bar::-webkit-scrollbar { display: none; }
.brand { font-size: 20px; font-weight: 700; margin: 0 6px; letter-spacing: -.01em; }
.spacer { flex: 1 1 auto; min-width: 4px; }
.group {
  display: flex; align-items: center; gap: 2px;
  padding: 2px; border-radius: 12px; background: #f1f2f6;
  flex: 0 0 auto;
}

.btn {
  appearance: none; border: 0; background: transparent; color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 10px; padding: 8px 12px; min-height: 40px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { background: rgba(0,0,0,.06); }
.btn:disabled { opacity: .3; cursor: default; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: #fff; padding: 8px 14px; }
.btn.ghost { background: #f1f2f6; padding: 8px 14px; }
.btn.danger { color: #b23b3b; background: #fbeaea; }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.icon { width: 40px; height: 40px; padding: 0; }
.btn.icon svg { width: 22px; height: 22px; }
.btn[aria-pressed="true"] { background: #fff; color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.ink-only[hidden] { display: none !important; }

.size i { display: block; border-radius: 50%; background: currentColor; }

.swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; padding: 0; margin: 3px 1px; }
.swatch i { display: block; width: 100%; height: 100%; border-radius: 50%; border: 1px solid rgba(0,0,0,.12); }
.swatch[aria-pressed="true"] { border-color: var(--accent); background: transparent; box-shadow: none; }

.pp { display: block; width: 20px; height: 20px; border: 1px solid #b7bccb; border-radius: 3px; background-color: #fff; }
.pp-lines { background-image: linear-gradient(to bottom, transparent 4px, var(--line) 4px, var(--line) 5px); background-size: 100% 5px; }
.pp-grid { background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px); background-size: 5px 5px; }
.pp-dots { background-image: radial-gradient(var(--dot) 1px, transparent 1.2px); background-size: 5px 5px; background-position: 2px 2px; }

.dot { display: block; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px #fff, 0 0 0 4px rgba(0,0,0,.12); }

.title {
  flex: 0 1 260px; min-width: 120px;
  border: 0; border-radius: 10px; background: #f1f2f6;
  font: inherit; font-weight: 600; color: var(--ink);
  padding: 8px 12px; min-height: 40px; outline: none;
}
.title:focus { background: #e8ecfb; }

/* ---------- segmented control / search ---------- */
.subbar {
  flex: 0 0 auto; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 12px 16px 0; padding-left: calc(16px + env(safe-area-inset-left)); padding-right: calc(16px + env(safe-area-inset-right));
}
.seg { display: inline-flex; background: #fff; border-radius: 12px; padding: 3px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.06); }
.seg button {
  appearance: none; border: 0; background: transparent; font: inherit; font-weight: 600; color: var(--muted);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; min-height: 38px; -webkit-tap-highlight-color: transparent;
}
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.seg button[data-area="praca"][aria-pressed="true"] { background: var(--praca); }
.seg button[data-area="firma"][aria-pressed="true"] { background: var(--firma); }
.search {
  flex: 1 1 220px; min-width: 180px; border: 0; border-radius: 12px; background: #fff;
  padding: 10px 14px; font: inherit; min-height: 44px; outline: none; color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.06);
}
.search:focus { box-shadow: inset 0 0 0 2px var(--accent); }

/* ---------- writing surface ---------- */
#stage {
  flex: 1 1 auto; position: relative; overflow: hidden;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  background: var(--bg);
  cursor: crosshair;
}
#stage canvas { position: absolute; left: 0; top: 0; pointer-events: none; }

.text {
  flex: 1 1 auto; border: 0; resize: none; outline: none; display: block; width: 100%;
  background: var(--paper); color: var(--ink);
  font: 17px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding: 24px clamp(20px, 10vw, 180px) calc(40px + env(safe-area-inset-bottom));
}
.text[hidden] { display: none; }

.pagenav {
  position: absolute; z-index: 2; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: 999px;
  background: rgba(255,255,255,.94); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  box-shadow: 0 4px 18px rgba(0,0,0,.14), 0 0 0 1px rgba(0,0,0,.05);
  -webkit-user-select: none; user-select: none;
}
.pagenav .btn { min-width: 40px; height: 40px; padding: 0 10px; border-radius: 999px; font-size: 22px; line-height: 1; }
.pagenav .label { padding: 0 6px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- notes list ---------- */
.notes {
  flex: 1 1 auto; overflow: auto; -webkit-overflow-scrolling: touch;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px;
  padding: 14px 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom));
  padding-left: calc(16px + env(safe-area-inset-left)); padding-right: calc(16px + env(safe-area-inset-right));
  align-content: start;
}
.notes[hidden] { display: none; }
.card {
  background: #fff; border-radius: 14px; overflow: hidden; position: relative;
  box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 6px 18px rgba(0,0,0,.05);
  cursor: pointer; -webkit-user-select: none; user-select: none;
}
.card:active { transform: scale(.985); }
.card .thumb { aspect-ratio: 4 / 3; background: var(--paper); display: block; border-bottom: 1px solid #eef0f4; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .thumb.textthumb {
  padding: 34px 14px 0; font-size: 12.5px; line-height: 1.45; color: #3a3d46; overflow: hidden; white-space: pre-wrap; word-break: break-word;
  -webkit-mask-image: linear-gradient(#000 65%, transparent); mask-image: linear-gradient(#000 65%, transparent);
}
.card .area {
  position: absolute; top: 10px; left: 10px; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: #fff; padding: 3px 8px; border-radius: 999px; background: var(--accent);
}
.card .area.praca { background: var(--praca); }
.card .area.firma { background: var(--firma); }
.card .meta { padding: 10px 12px 12px; }
.card .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .date { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.card .tag { font-size: 12px; color: var(--accent); background: #eef2ff; border-radius: 6px; padding: 2px 7px; }
.card .del {
  position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.9); color: #b23b3b; font-size: 20px; line-height: 1;
  box-shadow: 0 1px 3px rgba(0,0,0,.2); cursor: pointer;
}
.empty { margin: auto; color: var(--muted); text-align: center; padding: 24px; }

/* ---------- panels ---------- */
.panel {
  position: absolute; z-index: 3;
  top: calc(60px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right));
  width: min(380px, calc(100vw - 20px));
  background: #fff; border-radius: 14px; padding: 14px 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,.18), 0 0 0 1px rgba(0,0,0,.05);
}
.panel.left { right: auto; left: calc(10px + env(safe-area-inset-left)); }
.panel h2 { font-size: 16px; margin: 0 0 8px; }
.panel .row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid #eef0f4; }
.panel .row.col { flex-direction: column; align-items: stretch; gap: 6px; }
.panel .row span { flex: 1 1 auto; }
.panel .row b { color: var(--muted); font-weight: 500; }
.panel input[type="range"] { width: 100%; }
.panel input[type="checkbox"] { width: 22px; height: 22px; }
.panel input[type="text"] { border: 0; border-radius: 10px; background: #f1f2f6; font: inherit; padding: 10px 12px; min-height: 42px; outline: none; }
.panel input[type="text"]:focus { background: #e8ecfb; }
.panel .btn { background: #f1f2f6; }
.panel .btn.danger { background: #fbeaea; }
.panel .seg { align-self: flex-start; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; white-space: normal; }

.stats {
  position: absolute; z-index: 3; left: calc(10px + env(safe-area-inset-left)); bottom: calc(10px + env(safe-area-inset-bottom));
  margin: 0; padding: 8px 10px; border-radius: 10px;
  background: rgba(20,22,30,.82); color: #e8ecf5; font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace;
  pointer-events: none; white-space: pre;
}

/* ---------- calendar ---------- */
.btn.small { min-height: 36px; padding: 6px 12px; }
.calendar {
  flex: 1 1 auto; overflow: auto; -webkit-overflow-scrolling: touch;
  display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; align-content: start;
  padding: 14px 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom));
  padding-left: calc(16px + env(safe-area-inset-left)); padding-right: calc(16px + env(safe-area-inset-right));
}
.calendar[hidden] { display: none; }
@media (max-width: 860px) { .calendar { grid-template-columns: 1fr; } }
.cal-main { background: #fff; border-radius: 14px; padding: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.06); min-width: 0; }
.cal-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.cal-head h2 { flex: 1 1 auto; margin: 0; font-size: 18px; text-align: center; text-transform: capitalize; }
.cal-head .btn.icon { font-size: 24px; line-height: 1; }
.cal-dow { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; padding: 0 0 6px; text-align: center; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.cal-dow span:nth-child(n+6) { color: #b23b3b; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-cell {
  min-height: 88px; min-width: 0; border-radius: 10px; background: #f7f8fb; padding: 6px; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.03);
}
.cal-cell.other { opacity: .45; }
.cal-cell.sel { box-shadow: inset 0 0 0 2px var(--accent); background: #fff; }
.cal-cell .num { font-size: 13px; font-weight: 600; color: var(--muted); width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; border-radius: 50%; font-variant-numeric: tabular-nums; }
.cal-cell.today .num { background: var(--accent); color: #fff; }
.chip {
  appearance: none; border: 0; text-align: left; font: inherit; font-size: 11.5px; font-weight: 600; line-height: 1.3;
  color: #fff; padding: 3px 6px; border-radius: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: pointer; background: var(--accent); display: block; width: 100%;
}
.chip.praca { background: var(--praca); } .chip.firma { background: var(--firma); }
.chip.rem::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #fff; margin-right: 5px; vertical-align: 1px; box-shadow: 0 0 0 2px rgba(255,255,255,.35); }
.more { font-size: 11px; color: var(--muted); padding-left: 2px; }
.cal-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.side-sec { background: #fff; border-radius: 14px; padding: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.side-sec h3 { margin: 0 0 8px; font-size: 14px; }
.side-sec h3::first-letter { text-transform: uppercase; }
.side-list { display: flex; flex-direction: column; gap: 4px; }
.side-item {
  appearance: none; border: 0; background: #f7f8fb; border-radius: 10px; padding: 8px 10px; width: 100%;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: center;
  font: inherit; text-align: left; cursor: pointer; color: var(--ink);
}
.side-item .dot { width: 10px; height: 10px; box-shadow: none; }
.side-item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item .s { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.side-item.overdue .s { color: #b23b3b; font-weight: 600; }
.side-empty { color: var(--muted); font-size: 13px; margin: 4px 0; }
.side-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ---------- login ---------- */
.login { align-items: center; justify-content: center; padding: 20px; }
.login-box {
  width: min(380px, 100%); background: #fff; border-radius: 16px; padding: 28px 24px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 12px 40px rgba(0,0,0,.10);
  display: flex; flex-direction: column; gap: 12px; align-items: stretch; text-align: center;
}
.login-box img { align-self: center; border-radius: 14px; }
.login-box h1 { margin: 0; font-size: 22px; }
.login-box .muted { color: var(--muted); margin: 0; font-size: 14px; }
.login-box input {
  border: 0; border-radius: 10px; background: #f1f2f6; font: inherit; font-size: 17px; padding: 12px 14px; min-height: 46px; outline: none; text-align: center;
}
.login-box input:focus { background: #e8ecfb; }
.login-box .err { margin: 0; color: #b23b3b; font-size: 13px; min-height: 1.2em; }
.login-box .btn.primary { min-height: 46px; }
.panel .row > b { font-weight: 600; color: var(--ink); text-align: right; max-width: 55%; }

/* ---------- reminder banner ---------- */
.banner {
  position: absolute; z-index: 6; top: calc(62px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  max-width: calc(100vw - 20px); background: #1b1b1f; color: #fff; border-radius: 12px; padding: 8px 8px 8px 14px;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.28);
}
.banner[hidden] { display: none; }
.banner svg { width: 20px; height: 20px; fill: none; stroke: #fde047; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.banner .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.banner .btn { background: rgba(255,255,255,.14); color: #fff; min-height: 36px; padding: 6px 12px; }
.banner .btn.primary { background: var(--accent); }

.panel input[type="date"], .panel input[type="datetime-local"] {
  border: 0; border-radius: 10px; background: #f1f2f6; font: inherit; padding: 9px 12px; min-height: 42px; outline: none; color: var(--ink);
  flex: 1 1 auto; min-width: 0; -webkit-appearance: none; appearance: none;
}
.panel input[type="date"]:focus, .panel input[type="datetime-local"]:focus { background: #e8ecfb; }
.inline { display: flex; gap: 8px; align-items: center; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; padding-top: 6px; }
.check[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) { .card:active { transform: none; } }
