:root, [data-theme="dark"] {
  --bg: #0f1419;
  --card: #1a222c;
  --line: #2a3542;
  --text: #e8eef4;
  --muted: #8b9aab;
  --accent: #3d9cf0;
  --income: #3ecf8e;
  --expense: #f07178;
  --warn: #e6b450;
  --input: #12181f;
  --header: #0f1419ee;
  --surface-2: #12181f;
  --badge-ok: #1b3a2c;
  --badge-plan: #3a3320;
}
[data-theme="light"] {
  --bg: #f3f5f8;
  --card: #ffffff;
  --line: #d5dde6;
  --text: #1b2430;
  --muted: #5b6b7c;
  --accent: #2b7fd4;
  --income: #1a9b62;
  --expense: #c4454c;
  --warn: #b8860b;
  --input: #f7f9fb;
  --header: #fffffff2;
  --surface-2: #eef2f6;
  --badge-ok: #d9f3e6;
  --badge-plan: #f3e6c8;
}
[data-theme="light"] .tx.in { background: #dff3e8; }
[data-theme="light"] .tx.out { background: #f8dfe1; }
[data-theme="light"] .alert { background: #f8dfe1; color: #8f2b32; }
[data-theme="light"] .btn.danger { background: #c4454c; color: #fff; }
[data-theme="light"] .danger-zone { border-color: #e0a3a8; }
[data-theme="light"] .btn.primary, [data-theme="light"] .chip.active { color: #fff; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f5f8;
    --card: #ffffff;
    --line: #d5dde6;
    --text: #1b2430;
    --muted: #5b6b7c;
    --accent: #2b7fd4;
    --income: #1a9b62;
    --expense: #c4454c;
    --warn: #b8860b;
    --input: #f7f9fb;
    --header: #fffffff2;
    --surface-2: #eef2f6;
    --badge-ok: #d9f3e6;
    --badge-plan: #f3e6c8;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 15px/1.45 "Segoe UI", system-ui, sans-serif; }
.login-body { min-height: 100vh; display: grid; place-items: center; }
.login-card { background: var(--card); padding: 32px; border-radius: 16px; width: min(420px, 92vw); border: 1px solid var(--line); }
.logo { font-size: 28px; font-weight: 700; }
.muted { color: var(--muted); }
.alert { background: #3a1f24; color: #ffb4b8; padding: 10px 12px; border-radius: 8px; margin: 12px 0; }
label { display: block; margin: 12px 0; color: var(--muted); }
input, select, textarea { width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--input); color: var(--text); font-size: 16px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; margin: 0; }
.btn { border: 0; border-radius: 8px; padding: 10px 16px; cursor: pointer; font-weight: 600; background: var(--line); color: var(--text); text-decoration: none; }
.btn.primary { background: var(--accent); color: #061018; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { background: #5a2430; color: #ffd0d4; }
.top { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 16px; padding: 12px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--header); backdrop-filter: blur(8px); z-index: 5; }
.brand { font-weight: 700; font-size: 20px; }
nav { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 200px; }
.tab { background: transparent; color: var(--muted); border: 0; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.tab.active { background: var(--card); color: var(--text); }
main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 4px; overflow-wrap: anywhere; }
.calc-out { overflow-wrap: anywhere; }
.kpi-value.income { color: var(--income); }
.kpi-value.expense { color: var(--expense); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-size: 18px; }
.card-head { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.range-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.range-bar label { margin: 0; font-size: 13px; }
.range-bar input { width: auto; padding: 6px 8px; }
.chip { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; }
.chip.active { background: var(--accent); color: #061018; border-color: transparent; }
.sep { width: 1px; height: 20px; background: var(--line); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; align-items: start; }
.op-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-bottom: 12px; }
input[type="datetime-local"], input[type="date"], input[type="time"] { box-sizing: border-box; width: 100%; min-width: 0; max-width: 100%; height: 44px; min-height: 44px; line-height: 1.2; color-scheme: light dark; }
/* Custom native-icon replacement: iOS ignores height on temporal controls,
   so the control is flattened and the icon is drawn as background.
   The picker itself still opens on tap. lang/nav/theme selects stay native. */
input[type="datetime-local"], input[type="date"], input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Crect x='1' y='3' width='14' height='11' rx='2' fill='none' stroke='%238b9aab' stroke-width='1.5'/%3E%3Cpath d='M1 7h14M5 1v3M11 1v3' stroke='%238b9aab' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}
input[type="datetime-local"]::-webkit-date-and-time-value { margin: 0; width: 100%; text-align: center; }
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator { opacity: 0; }
/* Custom chevron for form/filter selects (iOS ignores height on native
   selects). lang/nav/theme/currency selects stay native by decision. */
.op-form select, .filters select, .safe-form select, #form-edit select, #safe-fx {
  -webkit-appearance: none;
  appearance: none;
  height: 44px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%238b9aab' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}
.range-bar input[type="date"], .date-chips input[type="date"] { width: auto; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; align-items: center; }
.filters input, .filters select { flex: 1 1 140px; min-width: 120px; max-width: 100%; }
.date-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 12px; }
.date-chips .chip { flex: none; }
.date-chips label { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; color: var(--muted); }
.date-chips input[type="date"] { width: auto; min-width: 140px; }
#tab-incomes .grid-2, #tab-expenses .grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); }

.table-wrap { overflow: auto; max-height: 420px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); position: sticky; top: 0; background: var(--card); z-index: 1; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.badge.done { background: var(--badge-ok); color: var(--income); }
.badge.plan { background: var(--badge-plan); color: var(--warn); }
.cat-list { list-style: none; padding: 0; margin: 12px 0 0; }
.cat-list li { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.modal { position: fixed; inset: 0; background: #0008; display: grid; place-items: center; z-index: 20; padding: 12px; overflow-y: auto; }
.modal.hidden { display: none; }
.modal-box { background: var(--card); padding: 20px; border-radius: 12px; width: min(420px, 100%); max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); overflow-y: auto; border: 1px solid var(--line); margin: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.brand { font-size: 17px; }
.calc { display: flex; flex-direction: column; gap: 10px; }
.calc-screen { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; text-align: right; }
.calc-expr { min-height: 18px; color: var(--muted); font-size: 13px; word-break: break-all; }
.calc-out { font-size: 28px; font-weight: 700; letter-spacing: 0.3px; }
.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.calc-keys button { padding: 14px 0; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-size: 18px; font-weight: 600; cursor: pointer; }
.calc-keys button.op { color: var(--accent); }
.calc-keys button.eq { background: var(--accent); color: #061018; border-color: transparent; }
.budget-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin: 12px 0 16px; }
.budget-row { display: flex; flex-direction: column; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; min-width: 0; }
.budget-row label { color: var(--text); }
.budget-row .row-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.over { color: var(--expense); font-weight: 700; }
.rest { color: var(--income); font-weight: 700; }
.danger-zone { border-color: #5a2430; }
.welcome-title { font-size: 28px; font-weight: 700; margin: 8px 0 4px; text-align: center; }
.welcome-box { text-align: center; }
.print-opts { display: flex; flex-wrap: wrap; gap: 12px 18px; margin: 8px 0 12px; }
.print-apps { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.print-app { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; max-height: 220px; overflow: auto; min-width: 0; }
.print-app h3 { margin: 0 0 8px; font-size: 14px; }
.print-app label { margin: 4px 0; font-size: 13px; }
.hp { position:absolute; left:-9999px; height:0; width:0; opacity:0; }
.icon-btn { color:var(--text); text-decoration:none; font-size:20px; min-width:40px; min-height:40px; padding:6px 8px; display:inline-flex; align-items:center; justify-content:center; background:transparent; border:1px solid var(--line); border-radius:8px; cursor:pointer; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.header-actions .btn, .header-actions .lang-select, .header-actions .icon-btn { height: 40px; min-height: 40px; max-height: 40px; box-sizing: border-box; font-size: 14px; line-height: 1.2; }
.header-actions .btn { display: inline-flex; align-items: center; justify-content: center; }
/* iOS draws <select> natively and zooms on focus below 16px: keep native look,
   but match the row box and kill the zoom. */
.header-actions .lang-select, .top select[data-lang-select] { font-size: 16px; }
.chat-link { border-color: var(--accent); }
.btn.sq { width: 36px; height: 36px; min-height: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 15px; }
td .btn.sq { margin: 1px; }
.avatar { width:72px; height:72px; border-radius:50%; object-fit:cover; background:var(--surface-2); }
.vault { background:linear-gradient(180deg,#2a1f16,#1a140f); border:8px solid #6b4f2a; border-radius:20px; padding:20px; }
.vault-wheel { width:90px; height:90px; margin:0 auto 12px; border-radius:50%; border:10px solid #c9a227; background:radial-gradient(circle,#eee 20%,#444 60%); }
.vault-door { text-align:center; }
.empty-safe { text-align:center; padding:28px 20px; border:1px dashed #c9a227; border-radius:16px; background:rgba(201,162,39,0.06); }
.empty-safe-glyph { font-size:44px; line-height:1; margin-bottom:10px; }
.empty-safe-title { font-size:22px; font-weight:700; color:#c9a227; margin-bottom:6px; }
.tx.in { background:#14301f; }
.tx.out { background:#3a1c20; }
.tx.usd td:nth-child(3) { color:#3ecf8e; }
.tx.eur td:nth-child(3) { color:#3d9cf0; }
.tx.uah td:nth-child(3) { color:#e6b450; }
.chat-layout { display:grid; grid-template-columns:280px 1fr; gap:12px; }
.chat-item { display:flex; gap:8px; align-items:center; width:100%; text-align:left; margin-bottom:6px; background:var(--surface-2); color:var(--text); border:1px solid var(--line); border-radius:8px; padding:8px; }
.chat-item.admin { border-color:#c9a227; }
.msgs { min-height:300px; max-height:60vh; overflow:auto; display:flex; flex-direction:column; gap:8px; }
.bubble { align-self:flex-start; background:var(--surface-2); padding:8px 10px; border-radius:10px; max-width:80%; }
.bubble.mine { align-self:flex-end; background:var(--badge-ok); }
.bubble.adm { border:1px solid #c9a227; }
.chat-send { display:flex; gap:8px; }
.chat-send input, .chat-send .btn { min-height:44px; }
.chat-send input { margin-top:0; }
.hidden { display:none !important; }
.nav-select { display:none; }
.chat-item.active, .user-pick.active { outline:2px solid var(--accent); }
.av { width:32px; height:32px; border-radius:50%; object-fit:cover; background:#2a3542; flex:none; }
.header-av { width:36px; height:36px; }
.av.ph { display:inline-block; }
.room-head { display:flex; gap:8px; align-items:center; margin-bottom:8px; }
.safe-form { display:grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap:8px; margin-bottom:12px; }
.safe-setup-form { display:flex; flex-direction:column; gap:10px; max-width:320px; margin:0 auto; }
.safe-setup-form input { margin-top:0; }
@media (max-width: 1100px) { .print-apps { grid-template-columns: 1fr; } }
@media (max-width: 900px) {
  .kpis, .grid-2, .chat-layout { grid-template-columns: 1fr; }
  .top { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .brand { font-size: 16px; }
  #nav-tabs { display:none; }
  .nav-select { display:block; width:100%; min-height:44px; }
  .op-form, .safe-form { grid-template-columns: 1fr !important; }
  .filters, .print-opts { flex-direction: column; align-items: stretch; }
  .op-form > * { min-width: 0; max-width: 100%; }
  input[type="datetime-local"], input[type="date"] { max-width: 100%; }
  /* Single geometry source for data inputs and search filters alike:
     identical declarations => identical boxes on iOS. appearance:none
     kills the native intrinsic padding of text/search/number controls
     (nothing to lose on these types, unlike date/select). */
  .op-form input, .op-form select, .op-form button,
  .filters input, .filters select {
    width: 100%; min-width: 0; max-width: 100%;
    height: 44px; min-height: 44px; max-height: 44px;
    line-height: 1.2; box-sizing: border-box;
    padding: 8px 12px; font-size: 16px; margin-top: 0;
  }
  .op-form select, .filters select { padding-right: 32px; }
  /* Same footprint as data inputs: full card width, no centering clamp. */
  .filters input, .filters select { max-width: none; margin-inline: 0; }
  .op-form input[type="text"], .op-form input[type="search"],
  .op-form input[type="number"], .op-form input[type="password"],
  .filters input[type="text"], .filters input[type="search"],
  .filters input[type="number"] {
    -webkit-appearance: none;
    appearance: none;
  }
  .filters { gap: 6px; }
  .chip, .icon-btn, .del-chat { min-height: 44px; }
  .chip { display: inline-flex; align-items: center; }
  .lang-select { min-height: 44px; font-size: 16px; }
  .sep { display: none; }
  .table-wrap { max-width:100%; overflow:auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 560px; }
  .btn { min-height: 44px; }
  .range-bar { flex-wrap: wrap; }
  .login-card { padding: 20px; width: min(420px, 94vw); }
  .modal-box { width: min(480px, 100%); }
  .chat-send { flex-direction: column; }
}
@media print {
  .top, .range-bar, .op-form, .filters, nav, form, .print-card, .calc-card { display: none !important; }
  .table-wrap, .print-app, .fc-table-wrap { max-height: none !important; overflow: visible !important; }
  .card { break-inside: avoid; }
}
.cap-img { display:block; width:100%; max-width:240px; height:76px; border-radius:8px; border:1px solid var(--line); background:var(--surface-2); margin-bottom:8px; }
.captcha-box { margin:14px 0; }

.vault .muted, .vault h2 { color:#d7c4a3; }
.card, .kpi, .calc-card { min-width:0; overflow:hidden; }

.widgets-row { align-items: stretch; }
.widgets-row > .card { display:flex; flex-direction:column; min-height: 420px; }
.widgets-row canvas { width:100% !important; min-width: 0; min-height: 0; }
/* Fixed-height wrapper: required by Chart.js with maintainAspectRatio:false.
   A bare canvas in an auto-height flex card causes a resize feedback loop
   (chart fills parent -> parent grows -> chart grows). */
.chart-box { position: relative; height: 280px; min-height: 0; }
.chart-box-pie { height: 260px; }
@media (max-width: 900px) {
  .widgets-row > .card { min-height: 360px; }
  .chart-box, .chart-box-pie { height: 300px; }
}
.calc { flex:1; }
@media (max-width: 900px) {
  .widgets-row > .card { min-height: 0; }
  #tab-incomes .grid-2, #tab-expenses .grid-2 { grid-template-columns: 1fr !important; }
  .op-form { display:flex; flex-direction:column; }
}

.calc-screen { display:flex; align-items:center; gap:10px; }
.calc-copy-btn { flex:none; width:40px; height:40px; border-radius:8px; border:1px solid var(--line); background:var(--card); color:var(--text); font-size:20px; line-height:1; cursor:pointer; }
.calc-copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.calc-screen-text { flex:1; min-width:0; text-align:right; }
.calc-copy-hint { margin: 4px 0 0; font-size:12px; }

.chat-link{position:relative;display:inline-flex;align-items:center;}
.chat-badge{position:absolute;top:-4px;right:-6px;min-width:16px;height:16px;padding:0 4px;border-radius:99px;background:var(--expense);color:#fff;font-size:10px;line-height:16px;text-align:center;}
.chat-unread{margin-left:auto;background:var(--accent);color:#061018;border-radius:99px;padding:1px 6px;font-size:11px;}
.chat-search-wrap{position:relative;margin-bottom:10px;}
.chat-list{overflow:visible;}
.chat-item{cursor:pointer;}
.del-chat{background:none;border:0;color:var(--muted);text-decoration:underline;cursor:pointer;font-size:12px;padding:6px 4px;white-space:nowrap;}
.del-chat:hover{color:var(--expense);}
.demo-btns{display:flex;gap:8px;flex-wrap:wrap;}
.demo-btns .btn{flex:1 1 auto;min-height:44px;}
.user-drop{position:absolute;left:0;right:0;top:100%;z-index:8;background:var(--card);border:1px solid var(--line);border-radius:8px;max-height:240px;overflow:auto;padding:6px;}
.user-drop .user-pick{display:flex;width:100%;gap:8px;align-items:center;margin:2px 0;}

.fc-cats .chk{display:flex;gap:6px;align-items:center;font-size:14px;}

.switch-row{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:12px 14px;border:1px solid var(--line);border-radius:12px;margin:12px 0;background:var(--surface-2,var(--card));}
.switch-row input{width:20px;height:20px;accent-color:var(--accent);}
.fc-toolbar{display:flex;gap:8px;margin:8px 0 12px;}
.fc-cats{display:grid;grid-template-columns:repeat(auto-fill,minmax(160px,1fr));gap:8px;}
.fc-chip{display:flex;align-items:center;gap:8px;margin:0;padding:10px 12px;border:1px solid var(--line);border-radius:12px;background:var(--card);cursor:pointer;}
.fc-chip:has(input:checked){border-color:var(--accent);background:var(--surface-2);}
.fc-chip input{accent-color:var(--accent);}
.fc-chip span{line-height:1.2;}

.lang-select,.top select[data-lang-select]{width:auto;min-width:64px;max-width:84px;flex:none;margin:0;padding:4px 6px;line-height:1.2;border-radius:8px;}
.header-actions{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin-left:auto;}
.back-btn{order:-1;}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px;}
.login-card select[data-lang-select]{width:auto;min-width:96px;}
.fc-table-wrap{max-height:min(52vh,420px);overflow:auto;-webkit-overflow-scrolling:touch;}
#tbl-fc-pick input[type="checkbox"]{width:18px;height:18px;margin:0;accent-color:var(--accent);flex:none;}
#tbl-fc-pick{width:100%;border-collapse:collapse;}
#tbl-fc-pick th,#tbl-fc-pick td{padding:10px 8px;border-bottom:1px solid var(--line);text-align:left;}
#tbl-fc-pick th:first-child,#tbl-fc-pick td:first-child{width:40px;}
#tbl-fc-pick tbody tr:active,#tbl-fc-pick tbody tr:hover{background:rgba(61,156,240,.08);}
