* { box-sizing: border-box; }
body { font-family: Arial, Helvetica, sans-serif; margin: 0; background: #f5f6f8; color: #222; }
.nav { background: #2f3e46; padding: 10px 20px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.nav a { color: #fff; text-decoration: none; }
.nav a:hover { text-decoration: underline; }
.nav-brand { font-weight: bold; }
.nav-user { margin-left: auto; color: #cbd5c0; }
main { padding: 20px; max-width: 1200px; margin: 0 auto; }
h1 { font-size: 22px; }
table.data { border-collapse: collapse; width: 100%; background: #fff; }
table.data th, table.data td { border: 1px solid #ddd; padding: 6px 10px; text-align: left; font-size: 14px; vertical-align: middle; }
table.data th { background: #4472c4; color: #fff; }
table.data th a.sort-link { color: #fff; text-decoration: none; }
table.data th a.sort-link:hover { text-decoration: underline; }
table.data tr.confirmed { background: #e2efda; }
table.detail { border-collapse: collapse; background: #fff; }
table.detail th { text-align: left; padding: 4px 10px; background: #eee; width: 260px; border: 1px solid #ddd; }
table.detail td { padding: 4px 10px; border: 1px solid #ddd; }
.filters { margin-bottom: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.filters input, .filters select { padding: 6px; }
.phone-filter { max-width: 160px; }
.status-form select { padding: 3px; max-width: 260px; }
.status-filter { position: relative; }
.status-filter summary { cursor: pointer; padding: 6px 10px; background: #fff; border: 1px solid #ccc; border-radius: 4px; list-style: none; }
.status-filter summary::-webkit-details-marker { display: none; }
.status-filter[open] summary { border-radius: 4px 4px 0 0; }
.status-checks { position: absolute; z-index: 5; background: #fff; border: 1px solid #ccc; border-top: none; padding: 8px 12px; min-width: 320px; max-height: 260px; overflow-y: auto; box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
.status-checks label { display: block; font-size: 13px; padding: 3px 0; white-space: nowrap; }
.clear-filters { align-self: center; font-size: 13px; color: #4472c4; }
.confirm-form { display: flex; align-items: center; justify-content: center; }
.confirm-form input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }
.pagination { margin-top: 14px; display: flex; gap: 12px; align-items: center; }
.flash { list-style: none; padding: 0; }
.flash li { padding: 8px 12px; margin-bottom: 8px; border-radius: 4px; }
.flash-success { background: #d4edda; color: #155724; }
.flash-error { background: #f8d7da; color: #721c24; }
.login-form { display: flex; flex-direction: column; gap: 10px; max-width: 320px; }
.login-form label { display: flex; flex-direction: column; gap: 4px; }
button { cursor: pointer; padding: 8px 14px; background: #4472c4; color: #fff; border: none; border-radius: 4px; }
button:hover { background: #35569c; }

/* Раскрывающиеся строки ФИО с неподтверждёнными номерами на странице статистики */
table.stats-table td.stats-expand-cell { padding: 0; }
.stats-row-details { width: 100%; }
.stats-row-summary {
  display: flex; cursor: pointer; list-style: none; padding: 6px 10px 6px 6px;
}
.stats-row-summary::-webkit-details-marker { display: none; }
.stats-row-summary::before { content: '▸'; color: #888; width: 16px; flex: 0 0 16px; }
.stats-row-details[open] > .stats-row-summary::before { content: '▾'; }
.stats-row-summary .stats-col { padding: 0 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats-row-summary .stats-col:nth-child(1) { flex: 0 0 calc(40% - 20px); }
.stats-row-summary .stats-col:nth-child(2) { flex: 0 0 20%; }
.stats-row-summary .stats-col:nth-child(3) { flex: 0 0 20%; }
.stats-row-summary .stats-col:nth-child(4) { flex: 0 0 20%; }
.stats-inner-table {
  width: calc(100% - 40px); margin: 0 10px 10px 30px; border-collapse: collapse; background: #f7f8fa;
}
.stats-inner-table th, .stats-inner-table td {
  border: 1px solid #ddd; padding: 4px 8px; font-size: 13px; text-align: left;
}
.stats-inner-table th { background: #dbe4f3; color: #1f2d3d; }

/* Страница "Персональные данные" */
table.personal-table th, table.personal-table td { font-size: 13px; }
.personal-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; max-width: 1000px; }
.personal-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.personal-form input { padding: 6px; }
.personal-form .form-buttons { grid-column: 1 / -1; display: flex; gap: 14px; align-items: center; }
.delete-form { margin-top: 24px; }
button.danger { background: #c0392b; }
button.danger:hover { background: #962d22; }

.megafon-form { display: flex; flex-direction: column; gap: 12px; max-width: 520px; }
.megafon-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.megafon-form textarea { padding: 6px; font-family: monospace; }
.megafon-form .form-buttons { display: flex; gap: 12px; }
.row-delete { padding: 4px 8px; font-size: 12px; }
.clear-db-form { display: inline; }

/* Администрирование */
.inline-form { display: inline-flex; align-items: center; gap: 6px; }
.inline-form input[type="password"] { padding: 4px; width: 140px; }
.admin-create-form { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; margin-top: 10px; }
.admin-create-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.admin-create-form input[type="text"], .admin-create-form input[type="password"] { padding: 6px; }
.admin-create-form .checkbox-label { flex-direction: row; align-items: center; gap: 6px; }

.owner-group { margin: 18px 0; border: 1px solid #d6dce5; border-radius: 6px; }
.owner-group > summary { padding: 14px; background: #edf2f8; cursor: pointer; }
.table-scroll { overflow-x: auto; }
.owner-group .data { margin: 0; }
.nav { flex-wrap: wrap; }

/* Shared theme tokens apply to every page, including login and admin. */
:root {
  color-scheme: light;
  --page-bg: #f5f6f8; --panel-bg: #ffffff; --text: #202b36;
  --border: #ccd4df; --muted: #566575; --group-bg: #e9eef6;
  --confirmed-bg: #e2efda; --link: #285ca8; --field-bg: #ffffff;
  --success-bg: #d4edda; --success-text: #155724;
  --error-bg: #f8d7da; --error-text: #721c24;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page-bg: #111923; --panel-bg: #1b2634; --text: #e5edf6;
  --border: #3b4c61; --muted: #b4c2d4; --group-bg: #2a3a50;
  --confirmed-bg: #213c32; --link: #9fc9ff; --field-bg: #15202e;
  --success-bg: #214b38; --success-text: #c0ebce;
  --error-bg: #552c36; --error-text: #ffd4dc;
}
body { background: var(--page-bg); color: var(--text); }
main { max-width: 1540px; }
a { color: var(--link); }
input, select, textarea { background: var(--field-bg); color: var(--text); border: 1px solid var(--border); border-radius: 3px; }
input[type="checkbox"] { accent-color: #4472c4; }
input::placeholder, textarea::placeholder { color: var(--muted); }
table.data, table.detail, .status-filter summary, .status-checks { background: var(--panel-bg); color: var(--text); }
table.data th, table.data td, table.detail th, table.detail td,
.stats-inner-table th, .stats-inner-table td, .status-filter summary, .status-checks { border-color: var(--border); }
table.detail th, .stats-inner-table th { background: var(--group-bg); color: var(--text); }
.stats-inner-table { background: var(--panel-bg); }
table.data tr.confirmed { background: var(--confirmed-bg); }
table.data .owner-heading td { padding: 6px 10px; background: var(--group-bg); border-top: 2px solid var(--border); }
.owner-heading span { color: var(--muted); font-size: 13px; }
.flash-success { background: var(--success-bg); color: var(--success-text); }
.flash-error { background: var(--error-bg); color: var(--error-text); }
#theme-toggle { padding: 6px 10px; border: 1px solid #708398; background: transparent; color: #ffffff; white-space: nowrap; }
#theme-toggle:hover { background: #405466; }
.nav-brand { color: #fff; }
.permissions-grid { display: grid; grid-template-columns: repeat(2, minmax(170px, 1fr)); gap: 6px 14px; margin-bottom: 10px; }
.permissions-grid label { display: flex; gap: 6px; align-items: start; font-size: 13px; }
.permissions-editor summary { cursor: pointer; margin-bottom: 8px; }
@media (max-width: 640px) {
  main { padding: 12px; }
  .permissions-grid { grid-template-columns: 1fr; }
  .nav { gap: 10px; padding: 10px 12px; }
}

/* Desktop: 100px on every outer edge, full remaining width (1920 -> 1720). */
body { min-height: 100vh; padding: 100px; }
main { width: 100%; max-width: none; margin: 24px 0 0; padding: 0; }
.nav { border-radius: 6px; }
.table-scroll, table.data { width: 100%; }
@media (max-width: 1000px) {
  body { padding: 24px; }
}
@media (max-width: 640px) {
  body { padding: 12px; }
  main { margin-top: 16px; padding: 0; }
}
.number-entry { background: var(--panel-bg); border: 1px solid var(--border); border-radius: 6px; padding: 12px; margin: 18px 0; }
.number-entry summary { cursor: pointer; font-weight: bold; }
.number-entry label { display: flex; flex-direction: column; gap: 6px; }
.number-entry textarea { width: 100%; max-width: 700px; padding: 8px; margin-bottom: 10px; }
/* KiB- Phone: full-width content with a collapsible navigation panel. */
.nav { background: var(--panel-bg); color: var(--text); border: 1px solid var(--border); padding: 16px 20px; }
.nav a, .nav-brand { color: var(--link); }
.nav-brand { font-size: 23px; }
.nav-user { color: var(--muted); }
#theme-toggle, #menu-toggle { background: var(--group-bg); color: var(--text); border: 1px solid var(--border); }
.app-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; margin-top: 24px; }
.app-layout.menu-hidden { grid-template-columns: minmax(0, 1fr); }
.app-layout > main { margin: 0; min-width: 0; }
.app-layout:not(:has(.sidebar)) { grid-template-columns: minmax(0, 1fr); }
.sidebar { background: var(--panel-bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; align-self: start; }
.sidebar[hidden] { display: none; }
.sidebar details { border-bottom: 1px solid var(--border); padding: 10px 0; }
.sidebar details:last-child { border: 0; }
.sidebar summary { font-weight: bold; cursor: pointer; padding: 6px; }
.sidebar a { display: block; padding: 9px 12px; border-radius: 5px; text-decoration: none; font-size: 14px; }
.sidebar a.active, .sidebar a:hover { background: var(--group-bg); color: var(--link); }
h1 { font-size: 26px; margin-top: 0; }
.panel, .settings-panel { background: var(--panel-bg); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin: 18px 0; }
.filters { align-items: end; }
.filters label { display: flex; flex-direction: column; gap: 6px; }
.filters input, .filters select { padding: 9px 12px; }
.table-scroll { border: 1px solid var(--border); border-radius: 7px; }
table.data th { background: var(--group-bg); color: var(--text); }
table.data th a.sort-link { color: var(--link); }
table.data td { padding: 10px; }
button { background: #1260df; border-radius: 5px; }
button.secondary { background: var(--group-bg); color: var(--link); }
.muted { color: var(--muted); }
.count-badge { font-size: 16px; background: var(--group-bg); padding: 4px 10px; border-radius: 15px; }
.state-label { display: block; color: var(--muted); margin-top: 4px; }
@media (max-width: 1000px) { .app-layout { grid-template-columns: 190px minmax(0,1fr); gap: 16px; } }
@media (max-width: 700px) { .app-layout { grid-template-columns: 1fr; } .sidebar { width: 100%; } }

/* KiB- Phone compact outer spacing */
body { padding: 12px; }
.nav { padding: 8px 12px; }
.app-layout { gap: 12px; margin-top: 12px; }
.sidebar { padding: 8px; }
@media (max-width: 1000px) {
  body { padding: 12px; }
  .app-layout { gap: 12px; }
}
@media (max-width: 640px) {
  body { padding: 8px; }
  .app-layout { gap: 8px; margin-top: 8px; }
}
