:root {
  color-scheme: light;
  --page: #f3fbf1;
  --page-2: #f8fff6;
  --bar: #eef7eb;
  --card: #e8f2e5;
  --card-2: #edf6ea;
  --chip: #dcebd8;
  --active: #d9f0df;
  --text: #142018;
  --secondary: #4f5e54;
  --muted: #6d7a70;
  --line: rgba(79, 94, 84, 0.14);
  --line-strong: rgba(22, 128, 79, 0.22);
  --accent: #17834f;
  --bright: #4df07a;
  --danger: #a94b56;
  --danger-soft: #ead8da;
  --white: #f8fff6;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page);
}

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--page);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.35;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
h3,
p,
dl,
ol {
  margin: 0;
}

h1 {
  color: var(--text);
  font-size: 1.85rem;
  font-weight: 760;
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 720;
  line-height: 1.2;
  letter-spacing: 0;
}

small,
.muted {
  color: var(--muted);
}

button,
.button,
input,
select {
  min-height: 40px;
  border-radius: 8px;
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--page-2);
  color: var(--text);
  padding: 0 11px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 650;
  cursor: pointer;
  text-align: center;
}

button:hover,
.button:hover {
  background: #126d43;
}

button:disabled,
.button.disabled {
  cursor: default;
  opacity: 0.78;
}

.button.secondary,
button.secondary {
  background: var(--chip);
  border-color: var(--line-strong);
  color: var(--accent);
}

.button.secondary:hover,
button.secondary:hover {
  background: #c9ddc7;
}

.button.ghost,
button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--secondary);
}

.button.danger,
button.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.button.danger-soft,
button.danger-soft,
.danger-soft {
  width: max-content;
  max-width: 100%;
  background: var(--danger-soft);
  border-color: rgba(169, 75, 86, 0.24);
  color: var(--danger);
}

.button.danger-soft:hover,
button.danger-soft:hover {
  background: #dfc3c7;
}

.button.tiny {
  min-height: 36px;
  padding: 0 11px;
  font-size: 0.84rem;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding: 5px 10px;
  background: rgba(243, 251, 241, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  flex: 0 0 34px;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

.brand-copy {
  display: grid;
  gap: 0;
  min-width: 0;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 0.98rem;
  font-weight: 760;
}

.brand small {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-links {
  display: none;
}

.page-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 8px 10px 72px;
}

.empty-state,
.mobile-section,
.admin-hero,
.admin-panel,
.notice {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.empty-state {
  display: grid;
  gap: 22px;
  max-width: 430px;
  margin: 8vh auto 0;
  padding: 24px 18px;
}

.login-brand {
  display: grid;
  justify-items: start;
  gap: 6px;
}

.login-brand strong {
  font-size: 1.5rem;
  line-height: 1;
}

.login-brand small {
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-error {
  color: var(--danger);
  font-weight: 650;
}

.dev-code {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--page-2);
  padding: 10px 11px;
  color: var(--secondary);
}

.cabinet-layout {
  display: block;
}

.cabinet-sidebar {
  display: none;
}

.cabinet-content,
.mobile-section {
  display: grid;
  gap: 10px;
}

.mobile-section {
  padding: 12px;
}

.page-title,
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.page-title {
  min-height: 0;
}

.page-title p,
.eyebrow {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0;
}

.section-head span {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 650;
}

.icon-button,
.square-button {
  display: grid;
  place-items: center;
  min-height: 0;
  border: 0;
  background: var(--chip);
  color: var(--text);
  font-weight: 680;
}

.icon-button {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  padding: 0;
  font-size: 1.35rem;
}

.icon-button.add {
  background: var(--active);
  color: var(--accent);
  font-size: 1.45rem;
}

.square-button {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  font-size: 1rem;
}

.home-dashboard {
  background: transparent;
  border: 0;
  padding: 0;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.sfa-card,
.status-card,
.device-card,
.history-card,
.pay-card,
.tariff-card,
.add-card,
.settings-card,
.profile-widget,
.admin-row-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.metric-card {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 78px;
  overflow: hidden;
  padding: 11px;
}

.card-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--chip);
  color: var(--accent);
  font-size: 1rem;
}

.metric-card h2 {
  color: var(--muted);
}

.metric-card strong {
  overflow-wrap: anywhere;
  font-size: 1rem;
  font-weight: 760;
  line-height: 1.15;
}

.metric-card small {
  padding-bottom: 10px;
  font-size: 0.86rem;
}

.status-card {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 90px;
  padding: 14px;
}

.status-card div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.status-card strong {
  color: var(--text);
  font-size: 1.55rem;
  font-weight: 780;
  line-height: 1.05;
}

.status-card small {
  font-size: 0.9rem;
}

.refill-button {
  width: 100%;
}

.profile-widget {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px;
}

.profile-widget-main {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.profile-doc {
  display: grid;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: var(--chip);
  color: var(--accent);
  font-size: 1.25rem;
}

.profile-widget-main div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.profile-widget strong {
  overflow: hidden;
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-actions {
  display: flex;
  grid-column: 1 / -1;
  gap: 8px;
}

.add-card,
.card-form,
.admin-form {
  display: grid;
  gap: 10px;
}

.admin-search {
  align-items: center;
}

.compact-access-form,
.compact-device-form {
  align-items: end;
}

.compact-access-form label,
.compact-device-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.compact-access-form .wide-field {
  grid-column: 1 / -1;
}

.compact-access-form button,
.compact-device-form button {
  justify-self: start;
}

.add-card,
.pay-card {
  padding: 10px;
}

.card-list,
.admin-card-list,
.tariff-list,
.log-list {
  display: grid;
  gap: 8px;
}

.device-card {
  display: grid;
  gap: 9px;
  padding: 11px;
}

.device-main {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.device-platform {
  width: max-content;
  max-width: 100%;
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--chip);
  color: var(--secondary);
  font-size: 0.78rem;
  font-weight: 650;
}

.device-actions {
  display: grid;
  gap: 7px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: max-content;
  max-width: 100%;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  background: var(--chip);
  color: var(--secondary);
  font-size: 0.78rem;
  font-weight: 650;
  white-space: nowrap;
}

.status-pill.is-on {
  border-color: rgba(77, 240, 122, 0.38);
  background: rgba(77, 240, 122, 0.26);
  color: #126d43;
}

.status-pill.is-off {
  border-color: rgba(169, 75, 86, 0.24);
  background: rgba(169, 75, 86, 0.08);
  color: var(--danger);
}

.pay-card {
  display: grid;
  gap: 8px;
}

.pay-tariffs {
  grid-template-columns: 1fr;
}

.tariff-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 10px;
  padding: 10px;
}

.tariff-card span {
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 760;
}

.tariff-card small {
  grid-column: 1 / -1;
}

.tariff-card button {
  grid-column: 1 / -1;
  margin-top: 3px;
}

.history-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
}

.history-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.history-head span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
  text-align: right;
}

.history-card .history-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.history-main span {
  overflow: hidden;
  color: var(--secondary);
  font-size: 0.88rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-card {
  padding: 0 12px;
}

.settings-card dl {
  display: grid;
}

.settings-card dl div {
  display: grid;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.settings-card dl div:last-child {
  border-bottom: 0;
}

.settings-card dt {
  color: var(--muted);
}

.settings-card dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-weight: 680;
}

.empty-note {
  padding: 10px 2px;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  min-height: 62px;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: var(--bar);
  border-top: 1px solid var(--line);
}

.bottom-nav a,
.cabinet-sidebar a {
  display: grid;
  place-items: center;
  gap: 2px;
  min-width: 0;
  border-radius: 8px;
  color: var(--secondary);
  font-size: 0.66rem;
  font-weight: 650;
}

.bottom-nav b,
.cabinet-sidebar b {
  overflow: hidden;
  max-width: 100%;
  font: inherit;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-icon {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  color: var(--accent);
  font-size: 1rem;
}

.bottom-nav a.active,
.bottom-nav a:hover,
.cabinet-sidebar a.active,
.cabinet-sidebar a:hover {
  background: var(--active);
  color: var(--text);
}

.bottom-nav a.active {
  margin: 3px 4px;
}

.admin-page .page-shell {
  padding-bottom: 28px;
}

.admin-hero {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
  padding: 16px;
}

.admin-hero div {
  display: grid;
  gap: 8px;
}

.notice {
  margin-bottom: 14px;
  padding: 14px;
}

.danger-notice {
  border-color: rgba(169, 75, 86, 0.28);
  background: var(--danger-soft);
  color: var(--danger);
}

.admin-grid {
  display: grid;
  gap: 12px;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.admin-tabs a {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--chip);
  padding: 0 12px;
  color: var(--secondary);
  font-size: 0.86rem;
  font-weight: 650;
}

.admin-tabs a.active {
  border-color: var(--line-strong);
  background: var(--active);
  color: var(--text);
}

.admin-panel {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.admin-dl {
  display: grid;
  gap: 0;
}

.admin-dl div {
  display: grid;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  padding: 9px 0;
}

.admin-dl div:last-child {
  border-bottom: 0;
}

.admin-dl dt {
  color: var(--muted);
}

.admin-dl dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 680;
}

.admin-actions,
.actions-cell {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.actions-cell form {
  margin: 0;
}

.admin-details {
  display: grid;
  gap: 10px;
}

.admin-details summary {
  width: max-content;
  max-width: 100%;
  cursor: pointer;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 700;
}

.inline-form {
  display: flex;
  gap: 8px;
}

.inline-form input {
  width: 96px;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--page-2);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

tr:last-child td {
  border-bottom: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 9px;
  font-size: 0.84rem;
  font-weight: 700;
}

.status-active {
  border-color: rgba(23, 131, 79, 0.28);
  background: var(--active);
  color: var(--accent);
}

.status-paid {
  border-color: rgba(23, 131, 79, 0.28);
  background: var(--active);
  color: var(--accent);
}

.status-pending,
.status-scheduled {
  border-color: rgba(120, 111, 70, 0.25);
  background: #f1ead3;
  color: #6f6534;
}

.status-expired,
.status-no_access,
.status-failed,
.status-canceled,
.status-cancelled,
.status-revoked,
.status-deleted,
.status-suspended,
.status-blocked {
  border-color: rgba(169, 75, 86, 0.24);
  background: var(--danger-soft);
  color: var(--danger);
}

.attention-row td {
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 650;
}

.admin-row-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
}

.admin-row-card div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.admin-row-card small {
  overflow-wrap: anywhere;
}

.log-list code {
  display: block;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--page-2);
  padding: 10px;
  color: var(--secondary);
}

@media (min-width: 560px) {
  .top-links {
    display: flex;
    gap: 8px;
  }

  .top-links a {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    border-radius: 999px;
    padding: 0 12px;
    background: var(--chip);
    color: var(--secondary);
    font-size: 0.86rem;
    font-weight: 650;
  }

  .page-shell {
    padding-right: 22px;
    padding-left: 22px;
  }

  .pay-tariffs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .add-card {
    grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  }

  .device-card {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
  }

  .device-actions {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .settings-card dl div {
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1fr);
  }

  .settings-card dd {
    text-align: right;
  }
}

@media (min-width: 900px) {
  h1 {
    font-size: 2rem;
  }

  .app-header {
    padding: 7px 24px;
  }

  .page-shell {
    padding-top: 16px;
    padding-bottom: 24px;
  }

  .cabinet-page .page-shell {
    max-width: 1120px;
  }

  .cabinet-layout {
    display: grid;
    grid-template-columns: 208px minmax(0, 1fr);
    gap: 16px;
    align-items: start;
  }

  .cabinet-sidebar {
    position: sticky;
    top: 66px;
    display: grid;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bar);
    padding: 10px;
  }

  .cabinet-sidebar a {
    grid-template-columns: 28px minmax(0, 1fr);
    justify-items: start;
    min-height: 48px;
    padding: 0 12px;
    font-size: 0.92rem;
  }

  .bottom-nav {
    display: none;
  }

  .mobile-section {
    padding: 16px;
  }

  .metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .status-card {
    grid-column: 1 / -1;
  }

  .metric-card {
    min-height: 90px;
  }

  .profile-widget {
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: start;
  }

  .profile-actions {
    grid-column: auto;
  }

  .pay-tariffs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .admin-hero {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .admin-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-panel.wide {
    grid-column: span 2;
  }

  .admin-form {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}
