:root {
  --brand: #d44a36;
  --brand-dark: #a3322b;
  --brand-soft: #fce8e5;
  --header-bg: #4d93dc;
  --header-bg-dark: #3a7bbd;
  --accent: #185fa5;
  --accent-soft: #e6f1fb;
  --bg: #f5f7f9;
  --card: #ffffff;
  --text: #17202a;
  --muted: #5f6b76;
  --line: #e2e7ec;
  --success: #0f6e56;
  --danger: #a32d2d;
  --danger-soft: #fcebeb;
  --warning: #854f0b;
  --warning-soft: #faeeda;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body { padding-bottom: 72px; }
body.no-nav { padding-bottom: 0; }

h1, h2, h3, h4 { margin: 0 0 8px; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
a { color: var(--accent); }

.brandbar {
  background: var(--header-bg);
  color: #fff;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .12);
}
.brandbar .who { margin-left: auto; text-align: right; font-size: 12px; line-height: 1.3; }
.brandbar .who strong { display: block; font-size: 14px; }
.brandbar button.link { background: none; border: 0; color: #d7e8f7; font-size: 12px; cursor: pointer; padding: 0; text-decoration: underline; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 14px 14px 26px; }
.wrap.narrow { max-width: 720px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card.tight { padding: 12px; }
.card h2 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card h2 .spacer { margin-left: auto; }

.grid { display: grid; gap: 12px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.c3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) {
  .grid.c2, .grid.c3 { grid-template-columns: 1fr; }
  .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 21px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.win { border-color: #9fe1cb; background: var(--brand-soft); }
.stat.lose { border-color: #f7c1c1; background: var(--danger-soft); }
.stat.warn { border-color: #fac775; background: var(--warning-soft); }

.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid transparent; }
.badge.gray { background: #f1efe8; color: #44443f; }
.badge.green { background: #e1f5ee; color: var(--brand-dark); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.blue { background: var(--accent-soft); color: var(--accent); }
.badge.amber { background: var(--warning-soft); color: var(--warning); }

.stat.week-done { background: var(--brand-dark); color: #fff; border-color: var(--brand-dark); }
.stat.week-done .label,
.stat.week-done .sub,
.stat.week-done .cheer { color: rgba(255,255,255,.85); }
.stat.week-done .cheer.win { color: #fff; }
.stat.week-done .cheer.lose { color: #ffd1d1; }
.stat.week-done .bar { background: rgba(255,255,255,.25); }
.stat.week-done .bar > span { background: #fff; }
.stat.week-open .bar > span { background: var(--brand); }


.cheer.win { color: var(--brand); }
.cheer.lose { color: var(--danger); }

.bar { height: 8px; background: #eceff2; border-radius: 999px; overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width .3s; }
.bar > span.low { background: #e24b4a; }
.bar > span.mid { background: #ef9f27; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f7faf9; }

input, select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 15px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}

/* typeable combobox with a custom suggestion dropdown (works on Android
   WebViews where <datalist> is unreliable) */
.combo-wrap { position: relative; }
.combo-wrap input { width: 100%; }
.combo-list {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  z-index: 40;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(15, 45, 36, 0.16);
  max-height: 200px;
  overflow-y: auto;
  display: none;
}
.combo-list li {
  padding: 9px 12px;
  font-size: 15px;
  cursor: pointer;
  color: var(--text);
}
.combo-list li:active, .combo-list li:hover { background: var(--brand-soft); }

textarea { min-height: 60px; resize: vertical; }
label { display: block; font-size: 12px; color: var(--muted); margin: 8px 0 4px; font-weight: 600; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }

button {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}
button:hover { background: var(--brand-dark); }
button.ghost { background: #fff; color: var(--brand); }
button.ghost:hover { background: var(--brand-soft); }
button.danger { background: #fff; color: var(--danger); border-color: #f0b3b3; }
button.danger:hover { background: var(--danger-soft); }
button.small { padding: 5px 9px; font-size: 12px; }
button:disabled { opacity: .55; cursor: not-allowed; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -6px 18px rgba(16, 24, 40, .07);
}
.nav button {
  flex: 1;
  background: none;
  border: 0;
  border-radius: 0;
  color: var(--muted);
  padding: 7px 4px 6px;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  position: relative;
  transition: color .15s ease;
}
.nav button .ico {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 26px;
  border-radius: 999px;
  transition: background .15s ease, transform .15s ease;
}
.nav button .lbl { letter-spacing: .01em; }
.nav button:active .ico { transform: scale(.92); }
.nav button.active { color: var(--brand); }
.nav button.active .ico { background: var(--brand-soft); }
.nav button.active::before {
  content: "";
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 26px; height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--brand);
}
@media (max-width: 480px) { .nav button { font-size: 10px; } .nav button .ico { width: 32px; } }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button { background: #fff; color: var(--muted); border: 1px solid var(--line); }
.tabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.rowline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.rowline > * { flex: 1 1 140px; }
.rowline > .auto { flex: 0 0 auto; }

.notice { padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; border: 1px solid; }
.notice.info { background: var(--accent-soft); border-color: #b5d4f4; color: #0c447c; }
.notice.ok { background: var(--brand-soft); border-color: #9fe1cb; color: var(--brand-dark); }
.notice.warn { background: var(--warning-soft); border-color: #fac775; color: var(--warning); }
.notice.bad { background: var(--danger-soft); border-color: #f7c1c1; color: var(--danger); }

.list-item { display: flex; gap: 8px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .grow .t { font-weight: 600; }
.list-item .grow .s { font-size: 12px; color: var(--muted); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .5);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100;
}
.modal { background: #fff; border-radius: 14px; max-width: 460px; width: 100%; padding: 20px; text-align: center; box-shadow: 0 20px 40px rgba(0,0,0,.2); }
.modal h2 { font-size: 19px; }
.modal .actions { margin-top: 16px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 4px 10px; border-radius: 999px; background: #f1efe8; font-size: 12px; font-weight: 600; }
.chip.S { background: #e1f5ee; color: #085041; }
.chip.A { background: #e6f1fb; color: #0c447c; }
.chip.B { background: #faeeda; color: #633806; }
.chip.C { background: #eeedfe; color: #3c3489; }
.chip.D { background: #f1efe8; color: #44443f; }

.bars { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.bars .b { display: grid; grid-template-columns: 92px 1fr 74px; gap: 8px; align-items: center; font-size: 13px; }
.bars .b .track { background: #eceff2; border-radius: 999px; height: 18px; overflow: hidden; }
.bars .b .track > span { display: block; height: 100%; border-radius: 999px; }
.bars .b .v { text-align: right; font-variant-numeric: tabular-nums; }

.syncbar { font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: #b4b2a9; }
.dot.on { background: #1d9e75; }
.dot.off { background: #e24b4a; }
.dot.pending { background: #ef9f27; }

.skeleton { height: 14px; background: #eceff2; border-radius: 6px; margin: 6px 0; }

.file-wrap { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.file-wrap input[type="file"] { display: none; }
.file-wrap label {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid var(--brand);
  border-radius: 8px;
  background: #fff;
  color: var(--brand);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin: 0;
}
.file-wrap label:hover { background: var(--brand-soft); }



/* ---------------------------------------------------------------- polish */
.brandbar {
  background: linear-gradient(135deg, var(--header-bg) 0%, var(--header-bg-dark) 100%);
  padding: 9px 14px;
  gap: 11px;
  box-shadow: 0 2px 10px rgba(16, 24, 40, .16);
}
.brandbar img {
  background: #fff;
  border-radius: 9px;
  padding: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}
.brandbar > div strong { font-size: 15px; letter-spacing: .01em; }
.brandbar .who { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.brandbar .who-me { text-align: right; line-height: 1.25; }
.brandbar .who-me strong { font-size: 13px; }
.brandbar .who-actions { display: flex; align-items: center; gap: 8px; }
.brandbar button.pill {
  position: relative;
  width: 38px; height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .35);
  background: rgba(255, 255, 255, .16);
  color: #fff;
  cursor: pointer;
  transition: background .15s ease, transform .12s ease;
}
.brandbar button.pill:hover { background: rgba(255, 255, 255, .3); }
.brandbar button.pill:active { transform: scale(.94); }
.brandbar button.pill.has-unread {
  background: #fff;
  color: var(--danger);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .28);
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(255, 255, 255, .28); }
  50% { box-shadow: 0 0 0 6px rgba(255, 255, 255, .12); }
}
.brandbar .pill-badge {
  position: absolute;
  top: -3px; right: -3px;
  min-width: 18px; height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  border: 2px solid var(--header-bg-dark);
}
.brandbar .burger {
  position: relative;
  width: 18px; height: 2px;
  background: currentColor;
  border-radius: 2px;
  display: block;
}
.brandbar .burger::before,
.brandbar .burger::after {
  content: "";
  position: absolute;
  left: 0; width: 18px; height: 2px;
  background: currentColor;
  border-radius: 2px;
}
.brandbar .burger::before { top: -6px; }
.brandbar .burger::after { top: 6px; }

.card {
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 14px rgba(16, 24, 40, .05);
  transition: box-shadow .18s ease, transform .18s ease;
}
.card:hover { box-shadow: 0 2px 6px rgba(16, 24, 40, .06), 0 10px 24px rgba(16, 24, 40, .07); }
.card h2 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .01em;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
.card h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

.stat {
  border-radius: 12px;
  padding: 12px 13px;
  background: #fff;
  border: 1px solid var(--line);
}
.stat .label { font-size: 11px; letter-spacing: .06em; }
.stat .value { font-size: 20px; letter-spacing: -.01em; }
.stat .sub { font-variant-numeric: tabular-nums; }

table { border-collapse: separate; border-spacing: 0; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); }
thead th {
  background: #f7f9fb;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .06em;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
thead th:first-child { border-top-left-radius: 8px; }
thead th:last-child { border-top-right-radius: 8px; }
tbody tr:nth-child(even) { background: #fcfdfd; }
tbody tr.clickable:hover { background: var(--brand-soft); }

button { box-shadow: 0 1px 2px rgba(16, 24, 40, .08); }
button:active { transform: translateY(1px); }
button.ghost { box-shadow: none; }

/* messages */
.msg {
  display: flex;
  gap: 11px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: 10px;
  margin-bottom: 10px;
  background: #fff;
}
.msg.unread {
  border-left-color: var(--danger);
  background: linear-gradient(90deg, var(--danger-soft) 0%, #fff 45%);
}
.msg-ico {
  flex: 0 0 34px;
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
}
.msg.unread .msg-ico { background: var(--danger-soft); color: var(--danger); }
.msg-body { flex: 1; min-width: 0; }
.msg-top { display: flex; align-items: center; gap: 7px; }
.msg-title { font-weight: 700; font-size: 14px; }
.dot-unread { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); display: inline-block; }
.msg-text { font-size: 13px; color: var(--text); margin-top: 2px; }
.msg-meta { font-size: 11px; color: var(--muted); margin-top: 5px; }
.msg-body > a { display: inline-block; margin-top: 8px; }

.empty-state {
  text-align: center;
  padding: 26px 12px;
  color: var(--muted);
  background: #fbfcfd;
  border: 1px dashed var(--line);
  border-radius: 12px;
}
.empty-state svg { opacity: .5; margin-bottom: 6px; }
.empty-state p { margin: 0; }

/* month picker (year + English month) */
.ympick { display: flex; gap: 8px; }
.ympick select { min-width: 0; }

/* forecast vs month target balance bar */
.fcbalance {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fbfcfd;
}
.fcbalance > div { flex: 1 1 120px; min-width: 0; }
.fcbalance span { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.fcbalance strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.fcbalance.ok { border-color: #9fe1cb; background: var(--brand-soft); }
.fcbalance.ok strong { color: var(--brand-dark); }
.fcbalance.bad { border-color: #f7c1c1; background: var(--danger-soft); }
.fcbalance.bad strong { color: var(--danger); }

/* tables scroll instead of breaking the page on narrow screens */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll.wide table { min-width: 660px; }

/* ------------------------------------------------------- mobile layout */
@media (max-width: 720px) {
  .wrap { padding: 12px 10px 22px; }
  .card { padding: 13px; border-radius: 12px; margin-bottom: 12px; }

  .grid { gap: 10px; }
  .grid.c2, .grid.c3 { grid-template-columns: 1fr; }
  .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* stack the date picker / Today / Print / Export controls instead of crushing them */
  .btnrow { gap: 8px; }
  .btnrow > * { flex: 1 1 calc(50% - 4px) !important; min-width: 0; }
  .btnrow > button, .btnrow > a { flex: 1 1 calc(50% - 4px) !important; }
  .btnrow > a { display: block; }
  .btnrow > a > button { width: 100%; }

  /* form rows: one control per line (inline flex styles are overridden) */
  .rowline { gap: 10px; }
  .rowline > * { flex: 1 1 100% !important; min-width: 0; }
  .rowline > .auto { padding-top: 0 !important; }
  .rowline input, .rowline select { width: 100%; }

  .stat .value { font-size: 18px; word-break: break-word; }
  .stat .sub { font-size: 12px; }

  table { font-size: 13px; }
  th, td { padding: 8px 6px; }

  /* Android/iOS WebView quirk: sub-16px controls zoom in on focus, which makes
     native dropdowns feel unclickable. Keep mobile controls at 16px and give
     selects a proper touch target. */
  input, select, textarea { font-size: 16px; }
  select { min-height: 42px; -webkit-tap-highlight-color: transparent; }
  .ympick select { min-height: 42px; }

  .brandbar { padding: 8px 10px; gap: 8px; }
  .brandbar > div strong { font-size: 14px; }
  .brandbar > div > div { display: none; }
  .brandbar .who-me strong { font-size: 12px; }
  .brandbar button.pill { width: 36px; height: 36px; }

  .card h2 { font-size: 15px; }
  .tabs button { flex: 1 1 auto; }
}

@media (max-width: 420px) {
  .grid.c4 { grid-template-columns: 1fr; }
  .btnrow > *, .btnrow > button, .btnrow > a { flex: 1 1 100% !important; }
  .fcbalance > div { flex: 1 1 100%; }
}

@media print {
  .nav, .brandbar button, .btnrow, .tabs { display: none !important; }
  body { background: #fff; padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}
