/* СПЕЦ — Админ-PWA. Мобильный интерфейс (iPhone-first). */
:root {
    --bg: #f2f4f7;
    --card: #ffffff;
    --ink: #14202e;
    --muted: #6b7886;
    --line: #e3e8ee;
    --brand: #0f2540;
    --brand-2: #1d4e89;
    --accent: #1d7fd6;
    --debt: #c0392b;       /* долг */
    --advance: #1e8e4e;    /* аванс/переплата */
    --warn: #d98a00;
    --ok: #1e8e4e;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
    margin: 0; padding: 0; height: 100%;
    background: var(--bg); color: var(--ink);
    font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    overscroll-behavior-y: none;
}
input, button, textarea { font: inherit; }
a { color: var(--accent); text-decoration: none; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }
[hidden] { display: none !important; }

/* ───── Вход ───── */
#screen-login {
    background: linear-gradient(160deg, var(--brand), var(--brand-2));
    align-items: center; justify-content: center; padding: 24px;
}
.login-box { width: 100%; max-width: 380px; }
.brand { text-align: center; color: #fff; margin-bottom: 28px; }
.brand-mark { font-size: 44px; font-weight: 800; letter-spacing: 4px; }
.brand-sub { opacity: .85; margin-top: 4px; }
.form { background: var(--card); border-radius: 16px; padding: 20px; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field textarea {
    width: 100%; padding: 12px 14px; border: 1px solid var(--line);
    border-radius: 10px; background: #fbfcfd; outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.primary {
    width: 100%; padding: 14px; border: 0; border-radius: 10px;
    background: var(--brand-2); color: #fff; font-weight: 600; font-size: 17px;
}
.primary:active { opacity: .85; }
.ghost { background: none; border: 0; color: var(--muted); padding: 8px; }
.hint { color: #cdd8e6; font-size: 13px; text-align: center; margin-top: 16px; }
.error { color: var(--debt); background: #fdecea; border-radius: 8px; padding: 10px; margin-top: 10px; font-size: 14px; }

/* ───── Каркас приложения ───── */
.topbar {
    display: flex; align-items: center; gap: 6px;
    padding: calc(8px + var(--safe-top)) 12px 8px;
    background: var(--brand); color: #fff;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar .t1 { font-weight: 700; font-size: 18px; }
.topbar .t2 { font-size: 12px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .ghost { color: #cdd8e6; }
.icon-btn { font-size: 20px; }
.back-btn { color: #cdd8e6; font-size: 16px; min-width: 44px; text-align: left; }

.content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 12px; }

/* ───── Нижние вкладки ───── */
.tabbar {
    display: flex; background: var(--card); border-top: 1px solid var(--line);
    padding-bottom: var(--safe-bottom);
}
.tabbtn {
    flex: 1; background: none; border: 0; color: var(--muted);
    padding: 8px 2px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 11px;
}
.tabbtn .ti { font-size: 21px; }
.tabbtn.active { color: var(--brand-2); }

/* ───── Поиск и фильтры ───── */
.toolbar { padding: 10px 12px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.search { width: 100%; padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fbfcfd; outline: none; }
.search:focus { border-color: var(--accent); }
.chips { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chip {
    flex: 0 0 auto; padding: 7px 14px; border: 1px solid var(--line);
    border-radius: 20px; background: #fff; color: var(--muted); font-size: 14px;
}
.chip.active { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }

/* ───── Списки ───── */
.list { padding: 8px 12px; display: flex; flex-direction: column; gap: 8px; }
.row {
    background: var(--card); border: 1px solid var(--line); border-radius: 12px;
    padding: 12px 14px; display: flex; align-items: center; gap: 10px;
}
.row:active { background: #f7f9fb; }
.row .main { flex: 1; min-width: 0; }
.row .r-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .r-sub { color: var(--muted); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .r-right { text-align: right; white-space: nowrap; }
.amount { font-weight: 700; }
.amount.debt { color: var(--debt); }
.amount.advance { color: var(--advance); }
.amount.zero { color: var(--muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.new { background: #e8f0fe; color: #1a56c4; }
.badge.in_work { background: #fff4e0; color: #b3730a; }
.badge.done { background: #e6f5ec; color: #1e8e4e; }
.badge.hold { background: #f0e8fb; color: #7b3fbf; }
.badge.cancelled { background: #f0f1f3; color: #6b7886; }
.badge.overdue { background: #fdecea; color: #c0392b; }
.badge.today { background: #fff4e0; color: #b3730a; }
.badge.upcoming { background: #e8f0fe; color: #1a56c4; }
.badge.muted { background: #f0f1f3; color: #6b7886; }

/* ───── Карточка деталей ───── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin: 12px; padding: 4px 14px; }
.card-title { font-weight: 700; padding: 10px 0 6px; color: var(--brand); }
.crow { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.crow:last-child { border-bottom: 0; }
.crow .k { color: var(--muted); font-size: 14px; flex: 0 0 auto; }
.crow .v { text-align: right; font-weight: 500; }
.phone-link { font-weight: 600; }

/* ───── Служебные ───── */
.loading, .empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty-icon { font-size: 40px; margin-bottom: 8px; }
.count { color: var(--muted); font-size: 13px; padding: 8px 14px 0; }
.sheet { background: var(--bg); }
