:root {
  font-family: "DM Sans", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1e293b;
  background: #f5f7fb;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --ink: #1e293b;
  --muted: #788397;
  --line: #e8ecf3;
  --blue: #4169e1;
  --blue-deep: #3156c5;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: #f5f7fb; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }

.topbar { height: 68px; display: flex; align-items: center; justify-content: space-between; padding: 0 max(28px, calc((100vw - 1200px) / 2)); background: #fff; border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; letter-spacing: -.35px; }
.brand-mark { display: grid; place-items: center; width: 31px; height: 31px; border-radius: 9px; color: #fff; background: linear-gradient(145deg, #637ff1, #385bc9); font-weight: 700; font-size: 16px; box-shadow: 0 4px 8px #4969dc30; }
.top-actions { display: flex; align-items: center; gap: 24px; color: #58657b; font-size: 14px; }
.top-actions a:hover, .link-button:hover { color: var(--blue); }
.top-actions form { margin: 0; }
.link-button { padding: 0; color: #58657b; border: 0; background: transparent; font-size: 14px; }
.main-shell { width: min(1200px, calc(100% - 48px)); min-height: calc(100vh - 127px); margin: 0 auto; padding: 42px 0 64px; }
.footer { padding: 20px; color: #9aa3b2; text-align: center; font-size: 12px; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.page-heading h1, .login-card h1 { margin: 4px 0 7px; color: var(--ink); font-size: clamp(24px, 3vw, 30px); letter-spacing: -.8px; }
.page-heading p, .login-card p { margin: 0; }
.eyebrow { color: #73819a; font-size: 11px; font-weight: 700; letter-spacing: 1.1px; text-transform: uppercase; }
.muted { color: var(--muted); font-size: 13px; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 16px; border: 1px solid transparent; border-radius: 8px; font-size: 13px; font-weight: 600; transition: background .15s, border-color .15s, transform .15s; }
.button:hover { transform: translateY(-1px); }
.button-primary { color: #fff; background: var(--blue); box-shadow: 0 4px 10px #4169e124; }
.button-primary:hover { background: var(--blue-deep); }
.button-secondary { color: #48566d; border-color: #dfe5ee; background: #fff; }
.button-secondary:hover { border-color: #bcc9dc; background: #fbfcff; }
.button-wide { width: 100%; }
.filters { display: flex; align-items: center; gap: 10px; padding: 15px; margin-bottom: 16px; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
.filters input, .filters select, .form-grid input, .form-grid select, .form-grid textarea, .stack-form input { width: 100%; min-height: 40px; padding: 9px 11px; border: 1px solid #dfe5ee; border-radius: 7px; outline: 0; color: #334155; background: #fff; font-size: 13px; }
.filters input:focus, .filters select:focus, .form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus, .stack-form input:focus { border-color: #8da4f3; box-shadow: 0 0 0 3px #4169e11a; }
.search-field { flex: 1 1 auto; min-width: 180px; }
.filters select { width: auto; min-width: 132px; }
.table-card, .form-card { overflow: hidden; border: 1px solid var(--line); border-radius: 11px; background: #fff; box-shadow: 0 2px 8px #1c315006; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th { padding: 13px 15px; color: #8390a3; background: #fbfcfe; text-align: left; font-size: 11px; font-weight: 600; }
td { padding: 15px; border-top: 1px solid #eef1f6; color: #4c596e; font-size: 12px; vertical-align: middle; }
tbody tr:hover { background: #fcfdff; }
.name-cell { min-width: 180px; color: #26334a; }
.subline { display: block; margin-top: 4px; color: #929caf; font-size: 11px; }
.tagline { display: block; max-width: 210px; overflow: hidden; margin-top: 5px; color: #7085c5; font-size: 10px; text-overflow: ellipsis; }
.category-pill { display: inline-block; padding: 4px 7px; border-radius: 5px; color: #526485; background: #f1f4f9; font-size: 10px; }
.status { display: inline-block; padding: 5px 8px; border-radius: 20px; font-size: 10px; font-weight: 600; }
.status-active { color: #32835a; background: #e9f7ef; }
.status-upcoming { color: #a36914; background: #fff4df; }
.status-today, .status-expired { color: #b94040; background: #fff0ef; }
.status-archived { color: #6e7788; background: #eef0f4; }
.renew-on { color: #4f8a67; font-size: 11px; }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.row-actions form { display: inline; margin: 0; }
.small-action { padding: 0; border: 0; background: transparent; color: #607089; font-size: 11px; }
.small-action:hover { color: var(--blue); }
.danger-text { color: #ba5656; }
.empty-state { padding: 70px 20px; text-align: center; }
.empty-icon { display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto 16px; border-radius: 18px; color: #6680e5; background: #edf1ff; font-size: 32px; font-weight: 300; }
.empty-state h2 { margin: 0 0 8px; font-size: 18px; }
.empty-state p { margin: 0 0 20px; }
.login-wrap { display: grid; min-height: 64vh; place-items: center; }
.login-card { width: min(410px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 13px; background: #fff; box-shadow: 0 10px 30px #263b5a0d; }
.login-card h1 { margin: 6px 0 8px; }
.stack-form { display: grid; gap: 17px; margin-top: 26px; }
.stack-form label, .form-grid label { display: grid; gap: 7px; color: #536178; font-size: 12px; font-weight: 600; }
.alert { padding: 11px 13px; margin: 0 0 16px; border-radius: 8px; font-size: 13px; }
.alert-error { border: 1px solid #f1d1cf; color: #a6423f; background: #fff3f2; }
.alert-success { border: 1px solid #cfe8d7; color: #287348; background: #f0fbf4; }
.form-heading { margin-bottom: 18px; }
.back-link { display: inline-block; margin-bottom: 17px; color: #71809a; font-size: 12px; }
.back-link:hover { color: var(--blue); }
.form-card { padding: 26px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 20px; }
.form-grid textarea { resize: vertical; }
.span-2 { grid-column: span 2; }
.checkbox-field { display: flex !important; align-items: flex-start; gap: 10px !important; padding: 13px; border-radius: 8px; background: #f7f9fc; }
.checkbox-field input { width: 16px; min-height: 16px; margin: 1px 0 0; accent-color: var(--blue); }
.checkbox-field span { display: grid; gap: 4px; }
.checkbox-field small { color: #8692a5; font-size: 11px; font-weight: 400; }
.form-footer { display: flex; justify-content: flex-end; gap: 9px; padding-top: 22px; margin-top: 24px; border-top: 1px solid var(--line); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.settings-card { padding: 26px; }
.settings-section + .settings-section { padding-top: 23px; margin-top: 23px; border-top: 1px solid var(--line); }
.settings-section h2, .action-card h2 { margin: 0 0 7px; color: #2b3850; font-size: 16px; }
.settings-section > .muted, .action-card > .muted { margin: 0 0 16px; line-height: 1.6; }
.form-grid small { color: #8692a5; font-size: 11px; font-weight: 400; line-height: 1.5; }
.settings-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.action-card { padding: 22px; }
.action-card form { margin: 0; }
.action-row { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.button-danger { color: #a6423f; border-color: #f1d1cf; background: #fff8f7; }
.button-danger:hover { background: #fff0ef; }
.log-result { display: inline-block; padding: 5px 8px; border-radius: 20px; font-size: 10px; font-weight: 600; color: #6e7788; background: #eef0f4; }
.log-sent, .log-test_sent { color: #32835a; background: #e9f7ef; }
.log-retrying { color: #a36914; background: #fff4df; }
.log-failed, .log-test_failed { color: #b94040; background: #fff0ef; }
.error-cell { max-width: 280px; white-space: normal; color: #a6423f; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card, .panel { border: 1px solid var(--line); border-radius: 11px; background: #fff; box-shadow: 0 2px 8px #1c315006; }
.stat-card { display: grid; gap: 11px; padding: 20px; }
.stat-card > span { color: #758198; font-size: 12px; }
.stat-card > strong { color: #26334a; font-size: 29px; line-height: 1; }
.stat-card > a { color: var(--blue); font-size: 11px; }
.stat-card-alert > strong { color: #b94040; }
.dashboard-columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; gap: 18px; }
.panel { padding: 22px; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 18px; }
.panel-heading h2, .category-costs h3 { margin: 0 0 6px; color: #2b3850; font-size: 16px; }
.panel-heading p { margin: 0; line-height: 1.5; }
.cost-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.cost-card { display: grid; gap: 8px; padding: 15px; border: 1px solid #edf0f6; border-radius: 9px; background: #fbfcff; }
.cost-card > span, .cost-card > small { color: #788397; font-size: 11px; }
.cost-card > strong { color: #293952; font-size: 20px; }
.category-costs { padding-top: 18px; margin-top: 18px; border-top: 1px solid var(--line); }
.category-costs h3 { font-size: 13px; }
.category-cost-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid #f0f2f7; color: #69768b; font-size: 12px; }
.category-cost-row:last-child { border-bottom: 0; }
.category-cost-row strong { color: #37445b; font-size: 12px; }
.upcoming-list { display: grid; }
.upcoming-item { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 12px 0; border-top: 1px solid #eef1f6; }
.upcoming-date { width: 82px; flex: 0 0 auto; color: #748198; font-size: 11px; }
.upcoming-name { display: grid; flex: 1; min-width: 0; gap: 4px; color: #36435a; font-size: 12px; }
.upcoming-name strong, .upcoming-name small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upcoming-name small { color: #8994a7; font-size: 10px; }
.upcoming-item .status { flex: 0 0 auto; }
.empty-inline { padding: 14px 0; margin: 0; color: #8994a7; font-size: 12px; }
.calendar-panel { overflow-x: auto; }
.calendar-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.calendar-toolbar h2 { margin: 0; color: #293952; font-size: 18px; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(105px, 1fr)); min-width: 735px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.calendar-weekday { padding: 10px 8px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); color: #8190a5; background: #fbfcfe; text-align: center; font-size: 11px; }
.calendar-day { min-height: 115px; padding: 8px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #fff; }
.calendar-day-outside { background: #fafbfc; }
.calendar-day-outside .calendar-date { color: #b6becb; }
.calendar-day-today { background: #f5f7ff; box-shadow: inset 0 0 0 1px #9caff8; }
.calendar-date { margin-bottom: 8px; color: #56647a; font-size: 11px; font-weight: 700; }
.calendar-event { display: block; overflow: hidden; padding: 5px 6px; margin: 4px 0; border-radius: 5px; color: #3d57aa; background: #edf1ff; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.calendar-event-billing { color: #8c611e; background: #fff3dc; }
.calendar-event:hover { background: #dfe6ff; }
.history-notes { max-width: 280px; white-space: normal; }
.data-actions { align-items: stretch; }
.data-actions .action-card { min-width: 0; }
.import-form { margin-top: 14px; }
.import-form small { color: #8692a5; font-size: 11px; line-height: 1.5; }
.import-form input[type="file"] { min-height: auto; padding: 8px; }

@media (max-width: 720px) {
  .topbar { height: auto; align-items: flex-start; flex-direction: column; gap: 10px; padding: 12px 18px; }
  .top-actions { width: 100%; flex-wrap: wrap; gap: 9px 14px; font-size: 12px; }
  .link-button { font-size: 12px; }
  .main-shell { width: calc(100% - 32px); padding-top: 28px; }
  .page-heading { align-items: flex-start; }
  .page-heading > .button { flex-shrink: 0; }
  .filters { align-items: stretch; flex-wrap: wrap; }
  .search-field { flex: 1 0 100%; }
  .filters label:not(.search-field) { flex: 1; }
  .filters select { width: 100%; min-width: 0; }
  .form-card { padding: 18px; }
  .form-grid { grid-template-columns: 1fr; gap: 15px; }
  .span-2 { grid-column: auto; }
  .settings-card { padding: 18px; }
  .settings-actions { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .stat-card { padding: 15px; }
  .dashboard-columns { grid-template-columns: 1fr; }
  .panel { padding: 17px; }
  .cost-grid { grid-template-columns: 1fr; }
  .calendar-toolbar .button { min-height: 36px; padding: 0 9px; font-size: 11px; }
  .calendar-toolbar h2 { font-size: 15px; text-align: center; }
  .upcoming-item { gap: 8px; }
  .upcoming-date { width: 72px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
