:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-strong: #f9fafb;
  --ink: #111827;
  --muted: #64748b;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --green: #0f766e;
  --green-dark: #0f5f59;
  --teal-soft: #e6fffb;
  --amber: #b45309;
  --amber-soft: #fff7ed;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
}

a {
  color: var(--blue);
}

.boot {
  display: grid;
  min-height: 100vh;
  place-items: center;
  color: var(--muted);
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  margin-bottom: 22px;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 0;
  background: transparent;
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-title {
  font-size: 17px;
  font-weight: 800;
  line-height: 1.2;
}

.brand-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
}

.nav button.active {
  color: var(--green-dark);
  background: #ecfdf5;
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--green);
}

.nav button:hover {
  color: var(--ink);
  background: #f3f4f6;
}

.nav-count {
  color: inherit;
  font-variant-numeric: tabular-nums;
}

.main {
  min-width: 0;
  padding: 26px 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green-dark);
  font-size: 13px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.25;
  letter-spacing: 0;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.6;
  font-size: 14px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  padding: 0 12px;
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
  text-decoration: none;
  font-size: 13px;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.button:hover,
.icon-button:hover {
  border-color: #9ca3af;
  background: #f9fafb;
}

.button.primary {
  color: white;
  border-color: var(--green);
  background: var(--green);
}

.button.primary:hover {
  border-color: var(--green-dark);
  background: var(--green-dark);
}

.button.danger {
  color: var(--red);
  border-color: #fecaca;
  background: var(--red-soft);
}

.button.small,
.icon-button.small {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.icon-button {
  width: 36px;
  padding: 0;
}

.grid {
  display: grid;
  gap: 16px;
}

.metrics {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.mini-metrics {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.metric-card {
  min-height: 108px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-value {
  margin-top: 12px;
  font-size: 27px;
  font-weight: 800;
  line-height: 1;
}

.metric-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.profit-text {
  color: var(--green-dark);
  font-weight: 700;
}

.danger-text {
  color: var(--red);
  font-weight: 700;
}

.section {
  margin-top: 24px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title {
  margin: 0;
  font-size: 17px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.table-wrap {
  overflow: auto;
}

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

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #f9fafb;
  font-size: 12px;
  font-weight: 700;
}

tbody tr:hover {
  background: #fbfdff;
}

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

.name-cell {
  min-width: 160px;
}

.strong {
  font-weight: 700;
}

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

.tiny {
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 700;
}

.badge.ok {
  color: var(--green-dark);
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.badge.due-soon {
  color: var(--amber);
  border-color: #fed7aa;
  background: var(--amber-soft);
}

.badge.overdue,
.badge.failed {
  color: var(--red);
  border-color: #fecaca;
  background: var(--red-soft);
}

.badge.not-renewing {
  color: var(--red);
  border-color: #fecaca;
  background: var(--red-soft);
}

.badge.no-date {
  color: var(--blue);
  border-color: #bfdbfe;
  background: var(--blue-soft);
}

.badge.ack {
  color: #854d0e;
  border-color: #fde68a;
  background: #fefce8;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) 160px auto;
  gap: 10px;
  margin-bottom: 12px;
}

.member-toolbar {
  display: flex;
  justify-content: flex-start;
}

.member-toolbar select {
  width: 180px;
}

.field,
.field-inline {
  display: grid;
  gap: 7px;
}

.field label,
.field-inline label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

textarea {
  min-height: 104px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

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

.form-grid .full {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.member-dialog-actions {
  justify-content: space-between;
  align-items: center;
}

.advanced-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
}

.advanced-box summary {
  min-height: 40px;
  padding: 10px 12px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.advanced-box .field {
  padding: 0 12px 12px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  gap: 16px;
}

.settings-panel {
  padding: 18px;
}

.settings-panel h2 {
  margin: 0 0 16px;
  font-size: 18px;
}

.telegram-settings-grid {
  align-items: stretch;
}

.telegram-side {
  height: 100%;
  grid-template-rows: auto minmax(0, 1fr);
}

.inline-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  color: var(--ink);
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 44px));
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.toast.error {
  color: var(--red);
  border-color: rgba(178, 55, 55, 0.35);
  background: var(--red-soft);
}

dialog {
  width: min(760px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background: var(--panel);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.dialog-title {
  margin: 0;
  font-size: 18px;
}

.dialog-body {
  padding: 18px 20px 20px;
}

.empty {
  padding: 26px;
  color: var(--muted);
  text-align: center;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 22px;
}

.login-box {
  width: min(420px, 100%);
  padding: 24px;
}

.login-box h1 {
  margin-bottom: 18px;
}

.link-output {
  width: 100%;
  min-height: 38px;
  padding: 10px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  overflow-wrap: anywhere;
  white-space: normal;
  background: #f9fafb;
}

.split-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.danger-zone {
  border-color: rgba(178, 55, 55, 0.24);
  background: #fffafa;
}

.notice {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #f9fafb;
}

.notice.warn {
  color: #7a4d00;
  border-color: rgba(183, 110, 0, 0.28);
  background: var(--amber-soft);
}

.variable-grid {
  display: grid;
  gap: 8px;
}

.variable-item {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
}

.variable-item code {
  color: var(--blue);
  font-weight: 700;
}

.variable-item span {
  color: var(--muted);
  font-size: 12px;
}

.calendar-toolbar {
  grid-template-columns: 220px;
}

.calendar-shell {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(124px, 1fr));
}

.calendar-weekdays {
  min-width: 868px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: #f9fafb;
  font-size: 12px;
  font-weight: 700;
}

.calendar-weekdays div {
  padding: 10px 12px;
}

.calendar-grid {
  min-width: 868px;
}

.calendar-cell {
  min-height: 132px;
  padding: 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.calendar-cell:nth-child(7n) {
  border-right: 0;
}

.calendar-cell.muted-cell {
  background: #f9fafb;
}

.calendar-day {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.calendar-events {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.calendar-event {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
  text-align: left;
}

.calendar-event span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-event.due-soon {
  border-color: rgba(183, 110, 0, 0.28);
  background: var(--amber-soft);
}

.calendar-event.overdue {
  border-color: rgba(178, 55, 55, 0.28);
  background: var(--red-soft);
}

.calendar-event.ack {
  background: #f3edcf;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
  }

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

  .nav button {
    justify-content: center;
  }

  .nav .nav-count {
    display: none;
  }

  .main {
    padding: 18px;
  }

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

  .settings-grid,
  .toolbar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .topbar,
  .section-head {
    display: grid;
  }

  .actions {
    justify-content: flex-start;
  }

  .metrics,
  .form-grid,
  .nav {
    grid-template-columns: 1fr;
  }

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

/* Refined admin theme */
:root {
  --bg: #f4f6f4;
  --panel: #ffffff;
  --panel-strong: #f8faf8;
  --ink: #16201d;
  --muted: #66726f;
  --line: #dfe6e1;
  --line-strong: #c8d2cc;
  --green: #16735d;
  --green-dark: #0b4f40;
  --teal-soft: #e7f6f0;
  --amber: #a85f00;
  --amber-soft: #fff6e7;
  --red: #c53b3b;
  --red-soft: #fff0f0;
  --blue: #2c64b8;
  --blue-soft: #eef5ff;
  --shadow: 0 14px 36px rgba(23, 35, 31, 0.08);
}

body {
  background:
    linear-gradient(180deg, #fbfcfb 0, var(--bg) 260px);
  letter-spacing: 0;
}

.app-shell {
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  padding: 24px 18px;
  color: rgba(255, 255, 255, 0.86);
  border-right: 0;
  background: #102a24;
  box-shadow: 10px 0 28px rgba(16, 42, 36, 0.12);
}

.brand {
  align-items: center;
  min-height: 58px;
  margin-bottom: 26px;
  padding: 2px 2px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
}

.brand-title {
  color: #ffffff;
  font-size: 18px;
  letter-spacing: 0;
}

.brand-subtitle {
  color: rgba(255, 255, 255, 0.62);
}

.nav {
  gap: 7px;
}

.nav button {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid transparent;
  color: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
}

.nav button:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
}

.nav button.active {
  color: #073b30;
  background: #dff3e9;
  box-shadow: none;
}

.nav-count {
  min-width: 24px;
  padding: 2px 7px;
  border-radius: 999px;
  color: inherit;
  background: rgba(255, 255, 255, 0.14);
  text-align: center;
}

.nav button.active .nav-count {
  background: rgba(7, 59, 48, 0.1);
}

.main {
  padding: 28px 32px 40px;
}

.topbar {
  align-items: flex-start;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  color: var(--green-dark);
  font-size: 12px;
  letter-spacing: 0;
}

h1 {
  color: #0e1714;
  font-size: 28px;
  font-weight: 850;
}

.subtitle {
  color: #68746f;
}

.actions {
  align-items: center;
}

.button,
.icon-button {
  min-height: 36px;
  border-radius: 7px;
  border-color: var(--line-strong);
  color: #17201d;
  background: #ffffff;
  box-shadow: 0 1px 0 rgba(23, 35, 31, 0.04);
  white-space: nowrap;
}

.button:hover,
.icon-button:hover {
  border-color: #9fb0a8;
  background: #f7faf8;
}

.button.primary {
  border-color: var(--green);
  background: var(--green);
  box-shadow: 0 8px 18px rgba(22, 115, 93, 0.18);
}

.button.primary:hover {
  border-color: var(--green-dark);
  background: var(--green-dark);
}

.button.danger {
  color: var(--red);
  border-color: #f3b8b8;
  background: #fff8f8;
}

.button.small,
.icon-button.small {
  min-height: 32px;
}

.metrics {
  grid-template-columns: repeat(6, minmax(152px, 1fr));
}

.mini-metrics {
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}

.metric-card {
  position: relative;
  min-height: 116px;
  padding: 17px 18px;
  overflow: hidden;
  border-color: var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.metric-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: #16735d;
}

.metric-card:nth-child(2)::before,
.metric-card:nth-child(5)::before {
  background: #b7791f;
}

.metric-card:nth-child(3)::before,
.metric-card:nth-child(6)::before {
  background: #2c64b8;
}

.metric-label {
  color: #68746f;
  font-size: 12px;
}

.metric-value {
  margin-top: 13px;
  color: #101816;
  font-size: 29px;
  letter-spacing: 0;
}

.metric-note {
  color: #6c7773;
}

.section {
  margin-top: 26px;
}

.section-head {
  margin-bottom: 12px;
}

.section-title {
  color: #111a17;
  font-size: 18px;
  font-weight: 800;
}

.panel {
  border-color: var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(23, 35, 31, 0.06);
}

.table-wrap {
  background: #ffffff;
}

table {
  min-width: 980px;
}

th,
td {
  padding: 13px 14px;
  border-bottom-color: var(--line);
}

th {
  color: #55635e;
  background: #f7faf8;
  font-size: 12px;
}

tbody tr:hover {
  background: #f8fbf9;
}

.strong {
  font-weight: 760;
}

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

.badge {
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
}

.badge.ok {
  color: #0b604f;
  border-color: #b7ead9;
  background: #eaf8f2;
}

.badge.due-soon {
  color: #9a5700;
  border-color: #f2d5a6;
  background: #fff4df;
}

.badge.overdue,
.badge.failed,
.badge.not-renewing {
  color: #b42323;
  border-color: #f2b6b6;
  background: #fff0f0;
}

.badge.no-date {
  color: #235aa3;
  border-color: #c8daf7;
  background: #eef5ff;
}

.badge.ack {
  color: #735312;
  border-color: #ead58e;
  background: #fff7cf;
}

input,
select,
textarea {
  min-height: 42px;
  border-color: #c9d4ce;
  border-radius: 7px;
  background: #ffffff;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(22, 115, 93, 0.13);
}

textarea {
  line-height: 1.55;
}

.toolbar {
  align-items: center;
}

.member-toolbar {
  margin-bottom: 14px;
}

.member-toolbar select,
.calendar-toolbar select {
  max-width: 220px;
}

.settings-grid {
  gap: 18px;
}

.settings-panel {
  padding: 20px;
}

.settings-panel h2 {
  color: #111a17;
  font-size: 18px;
}

.field label,
.field-inline label {
  color: #56625e;
}

.advanced-box,
.notice,
.link-output,
.variable-item {
  border-color: var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.notice.warn {
  color: #7a4a00;
  border-color: #efd39d;
  background: #fff7e8;
}

dialog {
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(16, 30, 26, 0.26);
}

dialog::backdrop {
  background: rgba(8, 18, 16, 0.56);
}

.dialog-head {
  padding: 18px 20px;
  background: #ffffff;
}

.dialog-title {
  font-size: 19px;
}

.dialog-body {
  padding: 20px;
}

.toast {
  border-radius: 8px;
  box-shadow: 0 16px 44px rgba(23, 35, 31, 0.14);
}

.calendar-shell {
  border-color: var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.calendar-weekdays {
  color: #56625e;
  background: #f7faf8;
}

.calendar-cell {
  min-height: 124px;
}

.calendar-event {
  border-color: #d8e2dc;
  background: #ffffff;
}

.calendar-event:hover {
  border-color: #aab9b1;
  background: #f8fbf9;
}

@media (max-width: 1220px) {
  .metrics {
    grid-template-columns: repeat(3, minmax(170px, 1fr));
  }

  .mini-metrics {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    height: auto;
    padding: 14px 14px 12px;
  }

  .brand {
    min-height: 46px;
    margin-bottom: 12px;
    padding-bottom: 10px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .brand-title {
    font-size: 16px;
  }

  .nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav button {
    flex: 0 0 auto;
    justify-content: center;
    min-height: 38px;
    padding: 0 12px;
  }

  .nav .nav-count {
    display: inline-flex;
    justify-content: center;
    margin-left: 6px;
  }

  .main {
    padding: 20px 18px 32px;
  }

  .topbar {
    display: grid;
    gap: 14px;
  }

  .actions {
    justify-content: flex-start;
  }

  .settings-grid,
  .telegram-settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  body {
    background: #f4f6f4;
  }

  .main {
    padding: 18px 12px 28px;
  }

  .topbar {
    margin-bottom: 18px;
  }

  h1 {
    font-size: 23px;
  }

  .subtitle {
    font-size: 13px;
  }

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

  .actions .button {
    width: 100%;
  }

  .metrics,
  .mini-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .metric-card {
    min-height: 104px;
    padding: 15px 14px;
  }

  .metric-value {
    font-size: 24px;
  }

  .section {
    margin-top: 22px;
  }

  .section-head {
    display: flex;
    align-items: center;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  .data-table,
  .data-table thead,
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .data-table thead {
    display: none;
  }

  .data-table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0;
  }

  .data-table tr {
    margin-bottom: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 10px 24px rgba(23, 35, 31, 0.07);
  }

  .data-table td {
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 10px;
    padding: 8px 0;
    border: 0;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .data-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  .data-table td:first-child {
    padding-top: 0;
  }

  .data-table td:last-child {
    padding-bottom: 0;
  }

  .data-table td[data-label="操作"] {
    display: block;
  }

  .data-table td[data-label="操作"]::before {
    display: block;
    margin-bottom: 8px;
  }

  .data-table .split-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  .data-table .split-actions .button {
    width: 100%;
    padding: 0 6px;
  }

  .member-toolbar select,
  .calendar-toolbar select {
    width: 100%;
    max-width: none;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  dialog {
    width: calc(100vw - 18px);
    max-height: calc(100dvh - 18px);
    overflow: hidden;
  }

  .dialog-head {
    padding: 14px 16px;
  }

  .dialog-body {
    max-height: calc(100dvh - 76px);
    overflow: auto;
    padding: 16px;
  }

  .form-actions,
  .member-dialog-actions,
  .split-actions {
    gap: 8px;
  }

  .member-dialog-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .member-dialog-actions > div:first-child {
    order: 2;
  }

  .member-dialog-actions > .split-actions {
    order: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .member-dialog-actions .button {
    width: 100%;
  }

  .calendar-shell {
    overflow-x: auto;
  }

  .calendar-weekdays,
  .calendar-grid {
    grid-template-columns: repeat(7, minmax(78px, 1fr));
    min-width: 546px;
  }

  .calendar-cell {
    min-height: 104px;
    padding: 8px;
  }

  .calendar-event {
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    min-height: 34px;
    padding: 6px 7px;
  }

  .calendar-event b {
    font-size: 12px;
  }
}

@media (max-width: 430px) {
  .main {
    padding-inline: 10px;
  }

  .brand-subtitle {
    display: none;
  }

  .actions,
  .metrics,
  .mini-metrics {
    grid-template-columns: 1fr;
  }

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

  .data-table .split-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toast {
    right: 10px;
    bottom: 10px;
    max-width: calc(100vw - 20px);
  }
}

/* Softer light theme override */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-strong: #fafbfc;
  --ink: #16181d;
  --muted: #68707d;
  --line: #e4e7ec;
  --line-strong: #cfd5dd;
  --green: #16805f;
  --green-dark: #0e664b;
  --teal-soft: #eaf7f1;
  --amber: #a15c07;
  --amber-soft: #fff6e6;
  --red: #c53636;
  --red-soft: #fff1f1;
  --blue: #2f5fcf;
  --blue-soft: #eef3ff;
  --shadow: 0 10px 26px rgba(19, 28, 42, 0.06);
}

body {
  background: var(--bg);
}

.app-shell {
  grid-template-columns: 258px minmax(0, 1fr);
}

.sidebar {
  color: var(--ink);
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: none;
}

.brand {
  border-bottom-color: var(--line);
}

.brand-title {
  color: var(--ink);
}

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

.nav button {
  color: #596272;
  background: transparent;
}

.nav button:hover {
  color: var(--ink);
  border-color: var(--line);
  background: #f5f7fb;
}

.nav button.active {
  color: #244bb3;
  border-color: #dbe5ff;
  background: #eef3ff;
  box-shadow: inset 3px 0 0 var(--blue);
}

.nav-count {
  background: #eef0f4;
}

.nav button.active .nav-count {
  color: #244bb3;
  background: #dfe8ff;
}

.topbar {
  border-bottom-color: #e6e9ee;
}

.eyebrow {
  color: #526071;
}

.button.primary {
  border-color: var(--blue);
  background: var(--blue);
  box-shadow: 0 8px 18px rgba(47, 95, 207, 0.16);
}

.button.primary:hover {
  border-color: #244bb3;
  background: #244bb3;
}

.metric-card {
  box-shadow: var(--shadow);
}

.metric-card::before {
  background: #2f5fcf;
}

.metric-card:nth-child(2)::before,
.metric-card:nth-child(5)::before {
  background: #d08b24;
}

.metric-card:nth-child(3)::before,
.metric-card:nth-child(6)::before {
  background: #16805f;
}

.panel,
.calendar-shell {
  box-shadow: var(--shadow);
}

.badge.ok {
  color: #0e664b;
  border-color: #bde8d8;
  background: #edf9f4;
}

.badge.due-soon {
  color: #8a5208;
  border-color: #efd8ad;
  background: #fff7e7;
}

.badge.no-date {
  color: #244bb3;
  border-color: #cfdbff;
  background: #eef3ff;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 95, 207, 0.13);
}

.notice.warn {
  color: #7b4a04;
  border-color: #ecd19b;
  background: #fff8e8;
}

@media (max-width: 980px) {
  .sidebar {
    position: static;
    padding: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    min-height: 42px;
    margin-bottom: 10px;
    padding: 0 2px 10px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand-title {
    font-size: 15px;
  }

  .brand-subtitle {
    font-size: 11px;
  }

  .nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    overflow: visible;
    padding-bottom: 0;
  }

  .nav button {
    width: 100%;
    min-height: 38px;
    padding: 0 9px;
    justify-content: space-between;
    border-color: var(--line);
    background: #ffffff;
    font-size: 13px;
  }

  .nav button.active {
    box-shadow: none;
  }

  .nav .nav-count {
    display: inline-flex;
    justify-content: center;
    margin-left: 6px;
    font-size: 12px;
  }
}

@media (max-width: 760px) {
  .main {
    padding: 16px 10px 26px;
  }

  .topbar {
    gap: 12px;
    padding-bottom: 14px;
  }

  h1 {
    font-size: 22px;
  }

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

  .button,
  .icon-button,
  input,
  select,
  textarea {
    min-height: 40px;
  }

  .metrics,
  .mini-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .metric-card {
    min-height: 96px;
    padding: 13px 12px;
  }

  .metric-value {
    margin-top: 10px;
    font-size: 22px;
  }

  .metric-note {
    margin-top: 8px;
    font-size: 11px;
  }

  .section-head {
    gap: 8px;
    margin-bottom: 10px;
  }

  .section-title {
    font-size: 16px;
  }

  .data-table tr {
    margin-bottom: 9px;
    padding: 10px 11px;
    box-shadow: none;
  }

  .data-table td {
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 8px;
    padding: 7px 0;
    font-size: 13px;
  }

  .data-table td::before {
    font-size: 11px;
  }

  .data-table .split-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .data-table .split-actions .button {
    min-height: 34px;
    font-size: 12px;
  }

  .table-wrap .empty {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
  }

  .settings-panel {
    padding: 14px;
  }

  .variable-item {
    grid-template-columns: 106px minmax(0, 1fr);
  }

  .dialog-body {
    padding: 14px;
  }

  .calendar-weekdays,
  .calendar-grid {
    grid-template-columns: repeat(7, minmax(72px, 1fr));
    min-width: 504px;
  }

  .calendar-cell {
    min-height: 96px;
  }
}

@media (max-width: 520px) {
  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .metrics,
  .mini-metrics {
    grid-template-columns: 1fr;
  }

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

  .metric-card::before {
    width: 3px;
    height: 100%;
    inset: 0 auto 0 0;
  }

  .data-table td {
    grid-template-columns: 68px minmax(0, 1fr);
  }

  .member-dialog-actions > .split-actions {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 390px) {
  .actions {
    grid-template-columns: 1fr;
  }

  .nav button {
    padding: 0 8px;
    font-size: 12px;
  }

  .data-table td {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .data-table td::before {
    color: #7a8492;
  }
}

/* Final mobile layout guard */
@media (max-width: 980px) {
  html,
  body {
    width: 100%;
    overflow-x: hidden;
  }

  .app-shell {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    padding: 12px 12px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: #ffffff;
  }

  .brand {
    margin-bottom: 10px;
  }

  .main {
    width: 100%;
    min-width: 0;
  }

  .topbar {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
  }
}

@media (max-width: 560px) {
  .sidebar {
    padding: 10px;
  }

  .brand {
    gap: 10px;
    min-height: 40px;
    padding-bottom: 9px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
  }

  .brand-title {
    max-width: calc(100vw - 74px);
    overflow: hidden;
    font-size: 15px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .brand-subtitle {
    display: none;
  }

  .nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .nav button {
    min-height: 36px;
    padding: 0 8px;
    border-radius: 7px;
    font-size: 12px;
  }

  .nav-count {
    min-width: 22px;
    padding: 1px 6px;
    font-size: 11px;
  }

  .main {
    padding: 14px 10px 24px;
  }

  .eyebrow {
    margin-bottom: 5px;
    font-size: 11px;
  }

  h1 {
    font-size: 22px;
  }

  .subtitle {
    max-width: 100%;
    font-size: 13px;
    line-height: 1.45;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 7px;
  }

  .actions .button {
    min-width: 0;
    width: 100%;
    padding: 0 8px;
    font-size: 12px;
  }

  .metrics,
  .mini-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .metric-card {
    min-height: 94px;
    padding: 13px 12px;
  }

  .metric-card::before {
    inset: 0 0 auto 0;
    width: 100%;
    height: 3px;
  }

  .metric-label {
    font-size: 11px;
  }

  .metric-value {
    font-size: 22px;
  }

  .metric-note {
    font-size: 11px;
    line-height: 1.35;
  }

  .section {
    margin-top: 20px;
  }

  .section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .member-toolbar {
    display: block;
  }

  .member-toolbar select,
  .calendar-toolbar select {
    width: 100%;
    max-width: none;
  }

  .data-table tr {
    border-radius: 8px;
  }

  .data-table td {
    grid-template-columns: 70px minmax(0, 1fr);
    font-size: 13px;
  }

  .settings-grid,
  .telegram-settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 400px) {
  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metrics,
  .mini-metrics,
  .actions {
    grid-template-columns: 1fr;
  }

  .data-table td {
    grid-template-columns: 64px minmax(0, 1fr);
  }
}
