*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green:       #3B6D11;
  --green-light: #EAF3DE;
  --green-mid:   #639922;
  --green-text:  #27500A;
  --red:         #A32D2D;
  --red-light:   #FCEBEB;
  --blue:        #185FA5;
  --blue-light:  #E6F1FB;
  --blue-text:   #0C447C;
  --gray-0:      #ffffff;
  --gray-1:      #f8f8f6;
  --gray-2:      #f1f0ec;
  --gray-3:      #e4e3de;
  --gray-4:      #c8c7c0;
  --gray-5:      #888780;
  --gray-6:      #444441;
  --gray-7:      #1a1a18;
  --border:      #e4e3de;
  --radius:      8px;
}

html, body { min-height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: var(--gray-7); background: var(--gray-1); }

/* ── ЛОГИН ── */
.login-screen { display: none; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login-screen.show { display: flex; }
.login-card { background: var(--gray-0); border: 1px solid var(--border); border-radius: 12px; padding: 28px 24px; width: 100%; max-width: 360px; }
.login-logo { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 600; color: var(--green); margin-bottom: 20px; }
.login-logo svg { width: 22px; height: 22px; }
.login-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.login-sub { font-size: 12px; color: var(--gray-5); margin-bottom: 16px; }
.login-err { display: none; font-size: 12px; color: var(--red); background: var(--red-light); border-radius: var(--radius); padding: 8px 10px; margin-bottom: 12px; }
.login-err:not(:empty) { display: block; }
.code-input { letter-spacing: 8px; font-size: 20px; text-align: center; }

/* ── ОБЩИЕ ЭЛЕМЕНТЫ ФОРМ ── */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field label { font-size: 11px; font-weight: 600; color: var(--gray-5); text-transform: uppercase; letter-spacing: .03em; }
.field input, .field select {
  height: 38px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; color: var(--gray-7); background: var(--gray-0); outline: none;
}
.field input:focus, .field select:focus { border-color: var(--green-mid); }
.hint { font-size: 11px; color: var(--gray-5); line-height: 1.5; }

.btn-primary {
  width: 100%; height: 42px; border: none; border-radius: var(--radius);
  background: var(--green); color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .15s; margin-top: 4px;
}
.btn-primary:hover { background: var(--green-text); }
.btn-link { margin-top: 12px; background: none; border: none; color: var(--gray-5); font-size: 12px; cursor: pointer; }
.btn-cancel { height: 36px; padding: 0 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--gray-1); font-size: 13px; cursor: pointer; color: var(--gray-6); }
.btn-add { height: 32px; padding: 0 14px; border: 1px dashed var(--green-mid); border-radius: var(--radius); background: var(--green-light); color: var(--green-text); font-size: 12px; font-weight: 600; cursor: pointer; }
.btn-more { width: 100%; height: 36px; margin-top: 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--gray-0); color: var(--gray-6); font-size: 12px; cursor: pointer; }

/* ── ОСНОВНОЙ ЭКРАН ── */
#topbar {
  height: 56px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--gray-0); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-title { display: flex; flex-direction: column; }
.acc-name { font-size: 14px; font-weight: 600; }
.acc-contract { font-size: 11px; color: var(--gray-5); font-family: monospace; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip { font-size: 12px; color: var(--gray-6); background: var(--gray-2); border: 1px solid var(--border); padding: 4px 10px; border-radius: 20px; }
.logout-btn { font-size: 12px; color: var(--gray-5); cursor: pointer; border: none; background: none; padding: 4px 8px; border-radius: var(--radius); }
.logout-btn:hover { background: var(--gray-2); color: var(--gray-7); }

#content { max-width: 640px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }

.balance-card {
  background: var(--gray-0); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; display: flex; justify-content: space-between; align-items: flex-start;
}
.balance-label { font-size: 11px; color: var(--gray-5); margin-bottom: 4px; }
.balance-big { font-size: 26px; font-weight: 700; }
.balance-big.pos { color: var(--green); }
.balance-big.neg { color: var(--red); }
.balance-sub { font-size: 11px; color: var(--gray-5); margin-top: 4px; }
.balance-status { font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 20px; }
.balance-status.active { background: var(--green-light); color: var(--green-text); }
.balance-status.blocked { background: var(--red-light); color: var(--red); }

.promise-banner {
  background: var(--green-light); border: 1px solid var(--green-mid); color: var(--green-text);
  border-radius: var(--radius); padding: 10px 12px; font-size: 12px; font-weight: 500;
}

/* ── "КАК ОПЛАТИТЬ" (кабинет физ.лиц, static/portal_fiz.html) — оплата
   происходит вне портала (Kaspi/OSMP по номеру договора), это просто
   подсказка, не форма оплаты, см. routers/kaspi.py. ── */
.pay-hint-card { background: var(--blue-light); border: 1px solid var(--blue); border-radius: var(--radius); padding: 14px 16px; }
.pay-hint-contract { font-size: 22px; font-weight: 700; font-family: monospace; color: var(--blue-text); margin: 6px 0; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab { padding: 10px 14px; border: none; background: none; font-size: 13px; font-weight: 500; color: var(--gray-5); cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--green-text); border-bottom-color: var(--green); }
.tab-content { display: flex; flex-direction: column; gap: 10px; }

.section-row { display: flex; justify-content: space-between; align-items: center; }
.section-title { font-size: 12px; font-weight: 600; color: var(--gray-5); text-transform: uppercase; letter-spacing: .03em; }

.point-card { background: var(--gray-0); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.point-card.inactive { opacity: .6; }
.point-top { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 8px; }
.point-top > div:first-child { min-width: 0; flex: 1 1 160px; }
.point-addr { font-weight: 600; font-size: 13px; }
.point-meta { font-size: 11px; color: var(--gray-5); margin-top: 2px; }
.badge { font-size: 10px; font-weight: 600; padding: 3px 8px; border-radius: 20px; white-space: nowrap; }
.badge-active { background: var(--green-light); color: var(--green-text); }
.badge-blocked { background: var(--red-light); color: var(--red); }
.conn-dot {
  display: inline-block; margin-right: 5px; font-size: 13px; font-weight: 700;
  line-height: 1; vertical-align: middle;
}
.conn-dot-online  { color: var(--green-mid); }
.conn-dot-offline { color: var(--red); }
.conn-dot-unknown { color: var(--gray-4); }
.point-actions { display: flex; gap: 6px; margin-top: 10px; }
.btn-pt-action { height: 28px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--gray-1); font-size: 11px; cursor: pointer; color: var(--gray-6); }
.cred-row { font-size: 11px; font-family: monospace; color: var(--gray-6); background: var(--gray-1); border-radius: 4px; padding: 4px 8px; margin-top: 4px; }

.hist-row { background: var(--gray-0); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.hist-row-top { display: flex; justify-content: space-between; align-items: center; }
.hist-type { font-size: 12px; font-weight: 600; }
.hist-pos { color: var(--green-text); }
.hist-neg { color: var(--red); }
.hist-row-meta { font-size: 11px; color: var(--gray-5); margin-top: 2px; }
.hist-row-details { font-size: 11px; color: var(--gray-6); margin-top: 4px; }

.user-row { display: flex; justify-content: space-between; align-items: center; background: var(--gray-0); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.user-row-name { font-weight: 600; font-size: 13px; }
.user-row-meta { font-size: 11px; color: var(--gray-5); }
.btn-delete-small { height: 26px; padding: 0 10px; border: 1px solid var(--red); border-radius: var(--radius); background: var(--red-light); color: var(--red); font-size: 11px; cursor: pointer; }

.empty-state { text-align: center; color: var(--gray-5); font-size: 12px; padding: 24px 0; }

/* ── ТРАФИК ── */
.field-row-inline { display: flex; gap: 10px; }
.field-row-inline .field { flex: 1; margin-bottom: 14px; }
.traffic-presets { display: flex; gap: 6px; margin-bottom: 14px; }
.traffic-total {
  background: var(--gray-0); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; text-align: center; font-size: 24px; font-weight: 700; color: var(--green-text);
}

/* ── МОДАЛКИ ── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); align-items: center; justify-content: center; z-index: 200; padding: 16px; }
.modal-overlay.open { display: flex; }
.modal { background: var(--gray-0); border-radius: 12px; width: 100%; max-width: 360px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 14px; font-weight: 600; }
.modal-close { font-size: 18px; cursor: pointer; color: var(--gray-5); border: none; background: none; }
.modal-body { padding: 16px; }
.modal-footer { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--gray-7); color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 12px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 300;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
