:root {
  --bg: #f5f6f8; --card: #ffffff; --text: #1d2430; --muted: #6b7484; --line: #e4e7ec;
  --accent: #3b6ef5; --accent-soft: #e8eefe; --firm: #8a5cf6; --firm-soft: #f1ebfe; --home: #10a37f;
  --home-soft: #e4f6f0; --warn: #d64545; --warn-soft: #fdecec; --pay: #c27c0e; --pay-soft: #fdf3e1;
  --radius: 12px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --card: #1b2029; --text: #e6e9ef; --muted: #8d96a6; --line: #2a313d;
    --accent: #6f95ff; --accent-soft: #1f2a44; --firm: #b197ff; --firm-soft: #2a2342; --home: #3fd0a6;
    --home-soft: #173229; --warn: #ff7676; --warn-soft: #3a1f22; --pay: #f0b04a; --pay-soft: #3a2e17;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; border: 0; border-radius: 8px; padding: 8px 14px; background: var(--accent); color: #fff; cursor: pointer; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button:hover { filter: brightness(1.05); }
input { font: inherit; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--text); min-width: 0; }
input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--warn); min-height: 1em; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { background: var(--card); padding: 32px; border-radius: var(--radius); box-shadow: var(--shadow); display: grid; gap: 12px; width: min(380px, 100%); }
.login-box h1 { margin: 0; }

.top { position: sticky; top: 0; z-index: 5; background: var(--bg); display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: center; padding: 14px 24px; border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 18px; white-space: nowrap; }
.brand .muted { font-weight: 400; font-size: 14px; margin-left: 8px; }
.logo { color: var(--accent); }
.quick { display: flex; gap: 8px; }
.quick input { flex: 1; }
.tabs { display: flex; gap: 6px; }
.tabs button { background: transparent; color: var(--muted); }
.tabs button.active { background: var(--accent-soft); color: var(--accent); }

.preview { margin: 16px 24px 0; background: var(--card); border: 1px solid var(--accent); border-radius: var(--radius); padding: 14px 18px; display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.preview-body { display: grid; gap: 4px; }
.preview-actions { display: flex; gap: 8px; }

.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; padding: 16px 24px 40px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; min-width: 0; }
.card.wide { grid-column: span 2; }
.card.full { grid-column: 1 / -1; }
.card h2 { font-size: 16px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.badge { background: var(--accent-soft); color: var(--accent); border-radius: 99px; padding: 0 8px; font-size: 13px; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.item { display: grid; grid-template-columns: 22px auto 1fr auto; gap: 8px; align-items: center; padding: 7px 6px; border-radius: 8px; }
.item:hover { background: var(--bg); }
.item .check { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); background: transparent; padding: 0; }
.item .check:hover { border-color: var(--home); background: var(--home-soft); }
.item .time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; min-width: 38px; }
.item .title { overflow-wrap: anywhere; }
.item .tags { display: flex; gap: 4px; }
.item.late .time { color: var(--warn); font-weight: 600; }
.item.done .title { text-decoration: line-through; color: var(--muted); }
.tag { font-size: 12px; border-radius: 6px; padding: 1px 6px; white-space: nowrap; }
.tag.firm { background: var(--firm-soft); color: var(--firm); }
.tag.personal { background: var(--home-soft); color: var(--home); }
.tag.high { background: var(--warn-soft); color: var(--warn); }
.tag.recur { background: var(--accent-soft); color: var(--accent); }
.empty { color: var(--muted); padding: 6px; }
.pay .amount { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.pay .pay-btn { background: var(--pay-soft); color: var(--pay); padding: 3px 10px; font-size: 13px; }

.item.mail { grid-template-columns: 22px 78px minmax(0, 1fr) auto; align-items: start; border-left: 3px solid transparent; }
.item.mail.hot { border-left-color: var(--warn); background: var(--warn-soft); }
.item.mail.money { border-left-color: var(--pay); }
.item.mail .snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .acts { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.mini { padding: 3px 8px; font-size: 13px; text-decoration: none; display: inline-block; }
.item.rule, .item.acc { grid-template-columns: 22px auto minmax(0, 1fr) auto; }
.item.rule.off, .item.acc.off { opacity: .5; }
.item .check.on { border-color: var(--home); background: var(--home); }
.rule-form { display: grid; gap: 8px; margin-top: 14px; }
.rule-opts { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
select { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--text); }
.tabs .badge { margin-left: 4px; }

.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.day { background: var(--bg); border-radius: 10px; padding: 8px; min-height: 110px; min-width: 0; }
.day h3 { font-size: 13px; margin: 0 0 6px; color: var(--muted); font-weight: 600; }
.day.today h3 { color: var(--accent); }
.chip { display: block; font-size: 12.5px; padding: 3px 6px; border-radius: 6px; margin-bottom: 3px; background: var(--card); border-left: 3px solid var(--home); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.firm { border-left-color: var(--firm); }
.chip.pay { border-left-color: var(--pay); background: var(--pay-soft); }

.links { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.link-group { grid-column: 1 / -1; font-size: 13px; color: var(--muted); font-weight: 600; margin-top: 6px; }
.link { position: relative; display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 10px; background: var(--bg); color: var(--text); text-decoration: none; min-width: 0; }
.link:hover { outline: 1px solid var(--accent); }
.link .av { flex: none; width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; color: #fff; font-weight: 700; }
.link .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link .x { position: absolute; top: 2px; right: 4px; padding: 0 6px; background: transparent; color: var(--muted); font-size: 14px; display: none; }
.link:hover .x { display: block; }
.link-form { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.link-form input { flex: 1 1 180px; }

#month { padding: 16px 24px 40px; }
.month-head { display: flex; align-items: center; gap: 16px; margin-bottom: 10px; }
.month-head h2 { margin: 0; min-width: 200px; text-align: center; }
.cal-days, .cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-days span { text-align: center; color: var(--muted); font-size: 13px; }
.cell { background: var(--card); border-radius: 10px; min-height: 110px; padding: 6px; min-width: 0; box-shadow: var(--shadow); }
.cell.other { opacity: .4; }
.cell.today { outline: 2px solid var(--accent); }
.cell .n { font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal-box { background: var(--card); border-radius: var(--radius); padding: 20px 24px; width: min(420px, 100%); display: grid; gap: 10px; justify-items: center; max-height: 100%; overflow: auto; }
.modal-box h2 { margin: 0; font-size: 17px; }
.modal-box img { background: #fff; border-radius: 8px; max-width: 100%; height: auto; }
.details { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; width: 100%; font-size: 14px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; cursor: copy; }
.pay .acts { display: flex; gap: 4px; align-items: center; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; }

@media (max-width: 1200px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card.wide { grid-column: 1 / -1; }
  .top { grid-template-columns: auto 1fr; }
  .top .tabs { grid-column: 1 / -1; }
}
@media (max-width: 960px) {
  .top { grid-template-columns: 1fr; padding: 12px 16px; }
  .grid { grid-template-columns: 1fr; padding: 12px 16px 40px; }
  .card.wide, .card.full { grid-column: auto; }
  .week { grid-template-columns: 1fr; }
  .item.mail { grid-template-columns: 22px minmax(0, 1fr); }
  .item.mail .time { display: none; }
  .item.mail .acts { grid-column: 2; justify-content: flex-start; }
  .day { min-height: 0; }
  #month { padding: 12px 8px; }
  .cell { min-height: 70px; padding: 4px; }
  .chip { font-size: 11px; }
}
