:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #64748b;
  --line: #d8dee9;
  --panel: rgba(255, 255, 255, 0.94);
  --bg: #eef3f8;
  --brand: #0f766e;
  --brand-2: #2563eb;
  --accent: #b45309;
  --danger: #b42318;
  --sidebar: #0f1f2e;
  --shadow: 0 18px 46px rgba(15, 23, 42, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #f7f9fc 0%, var(--bg) 46%, #f6f8fb 100%);
}

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

[hidden] {
  display: none !important;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 18px;
  color: #eef6ff;
  background:
    linear-gradient(180deg, rgba(15, 31, 46, 0.98), rgba(12, 47, 50, 0.96)),
    #0f1f2e;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #042f2e;
  background: #5eead4;
  font-weight: 800;
}

.eyebrow {
  color: #5eead4;
  font-size: 12px;
  letter-spacing: 0;
}

h1 {
  margin-top: 4px;
  font-size: 20px;
  font-weight: 760;
}

.side-nav {
  display: grid;
  gap: 8px;
}

button,
.button {
  border: 0;
  border-radius: 7px;
  padding: 10px 14px;
  min-height: 40px;
  background: #14b8a6;
  color: #062923;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}

button:hover,
.button:hover {
  filter: brightness(1.04);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.nav-item {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 13px 14px;
  color: #cbd5e1;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
}

.nav-item span {
  color: inherit;
  font-size: 15px;
}

.nav-item small {
  color: #94a3b8;
  font-size: 12px;
  font-weight: 500;
}

.nav-item.active,
.nav-item:hover {
  color: #f8fafc;
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(94, 234, 212, 0.28);
}

.nav-item.active small,
.nav-item:hover small {
  color: #ccfbf1;
}

.sidebar-card {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
}

.sidebar-card span {
  color: #94a3b8;
  font-size: 12px;
}

.sidebar-card strong {
  color: #ecfeff;
  font-size: 13px;
  line-height: 1.6;
}

.sidebar-export {
  display: block;
  text-align: center;
  color: #ecfeff;
  background: rgba(37, 99, 235, 0.55);
  border: 1px solid rgba(147, 197, 253, 0.32);
}

.sidebar-logout {
  display: block;
  text-align: center;
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.workspace {
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 28px 34px 20px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.24);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(14px);
}

.page-header .eyebrow {
  color: var(--brand);
  font-weight: 750;
}

h2 {
  margin-top: 5px;
  font-size: 27px;
  font-weight: 780;
}

.page-header p {
  max-width: 720px;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.65;
}

main {
  padding: 24px 34px 44px;
}

.view-panel {
  min-width: 0;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.panel {
  border: 1px solid rgba(148, 163, 184, 0.32);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.metric {
  min-height: 118px;
  padding: 16px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin: 10px 0 5px;
  color: #0f172a;
  font-size: 22px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

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

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

.layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  gap: 18px;
}

.company-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
}

.panel {
  padding: 18px;
  margin-bottom: 18px;
}

.entry-toolbar,
.panel-title,
.toolbar,
.filters {
  display: flex;
  align-items: center;
}

.entry-toolbar,
.panel-title {
  justify-content: space-between;
  gap: 16px;
}

.panel-title {
  margin-bottom: 14px;
}

.entry-toolbar > div,
.panel-title > div {
  min-width: 0;
}

h3 {
  font-size: 17px;
  font-weight: 760;
}

.entry-toolbar span,
.panel-title span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.toolbar,
.filters {
  gap: 10px;
}

.ghost {
  color: #1e3a8a;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
}

.muted-button {
  color: #334155;
  background: #e2e8f0;
}

.table-action {
  min-width: 48px;
  padding: 7px 10px;
  color: #0f766e;
  background: #ccfbf1;
  white-space: nowrap;
}

canvas {
  display: block;
  width: 100%;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 12px;
}

.form-section {
  grid-column: 1 / -1;
  padding-top: 4px;
  color: var(--brand);
  font-size: 13px;
  font-weight: 760;
}

label {
  display: grid;
  gap: 6px;
  color: #334155;
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

input:focus,
select:focus {
  outline: 2px solid rgba(20, 184, 166, 0.25);
  border-color: #14b8a6;
}

.wide {
  grid-column: span 2;
}

.form-section.wide {
  grid-column: 1 / -1;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
  overflow-wrap: anywhere;
}

th {
  color: #475569;
  background: #f1f5f9;
  font-weight: 750;
}

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

.tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  color: #115e59;
  background: #ccfbf1;
  font-size: 12px;
  white-space: nowrap;
}

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

.warn {
  color: var(--accent);
  font-weight: 700;
}

.stacked-cell {
  display: grid;
  gap: 4px;
}

.cell-subtle {
  color: var(--muted);
  font-size: 12px;
}

.status-badge {
  display: inline-block;
  width: fit-content;
  max-width: 100%;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
  font-size: 12px;
  white-space: nowrap;
}

.status-badge.completed {
  color: #115e59;
  background: #ccfbf1;
}

.status-badge.partial {
  color: #92400e;
  background: #fef3c7;
}

.status-badge.pending {
  color: #991b1b;
  background: #fee2e2;
}

.countdown-list {
  display: grid;
  gap: 10px;
}

.countdown-item {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #e5e7eb;
}

.countdown-item:last-child {
  border-bottom: 0;
}

.countdown-days {
  display: grid;
  place-items: center;
  min-height: 54px;
  border-radius: 8px;
  color: #92400e;
  background: #fef3c7;
}

.countdown-days.urgent {
  color: #991b1b;
  background: #fee2e2;
}

.countdown-days strong {
  font-size: 22px;
  line-height: 1;
}

.countdown-days span {
  font-size: 12px;
}

.countdown-main {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.countdown-main div {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.countdown-main strong,
.countdown-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 220px;
  color: var(--muted);
  font-size: 14px;
}

.company-list-panel {
  align-self: start;
}

.company-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  max-height: 720px;
  overflow: auto;
}

.company-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px;
  color: var(--ink);
  text-align: left;
  background: #fff;
  border: 1px solid #dbe3ee;
}

.company-item.active,
.company-item:hover {
  background: #ecfdf5;
  border-color: rgba(15, 118, 110, 0.38);
}

.company-item span,
.company-item-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.company-item strong,
.company-item small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.company-item small,
.company-item-meta small {
  color: var(--muted);
  font-weight: 500;
}

.company-item-meta {
  flex: 0 0 92px;
  text-align: right;
}

.company-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.mini-metric {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid #dbe3ee;
  border-radius: 8px;
  background: #f8fafc;
}

.mini-metric span,
.mini-metric small {
  color: var(--muted);
  font-size: 12px;
}

.mini-metric strong {
  font-size: 18px;
}

.tab-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.tab-button {
  color: #475569;
  background: #eef2f7;
}

.tab-button.active {
  color: #042f2e;
  background: #99f6e4;
}

.company-detail-panel table {
  min-width: 980px;
}

.empty-row {
  display: grid;
  place-items: center;
  min-height: 120px;
  color: var(--muted);
}

.quality-list {
  display: grid;
  gap: 10px;
}

.quality-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #e5e7eb;
  font-size: 14px;
}

.quality-item:last-child {
  border-bottom: 0;
}

.login-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at 16% 12%, rgba(94, 234, 212, 0.18), transparent 30%),
    linear-gradient(135deg, #081827 0%, #0f2f32 48%, #eef3f8 48.2%, #f6f8fb 100%);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 18px;
}

.login-card {
  width: min(440px, 100%);
  padding: 28px;
  border: 1px solid rgba(148, 163, 184, 0.38);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.22);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 18px;
  border-bottom: 1px solid #e5e7eb;
}

.login-brand .eyebrow {
  color: var(--brand);
  font-weight: 750;
}

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

.login-heading {
  margin: 22px 0 18px;
}

.login-heading h2 {
  font-size: 28px;
}

.login-heading p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.65;
}

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

.login-form button {
  margin-top: 4px;
  min-height: 46px;
}

.login-error {
  margin-bottom: 14px;
  padding: 11px 12px;
  border: 1px solid #fecaca;
  border-radius: 7px;
  color: #991b1b;
  background: #fef2f2;
  font-size: 13px;
  font-weight: 700;
}

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

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

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

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

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

  .sidebar-card {
    margin-top: 0;
  }

  .page-header,
  main {
    padding-left: 20px;
    padding-right: 20px;
  }
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    gap: 10px;
    padding: 12px;
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.16);
  }

  .brand-block {
    gap: 10px;
    padding: 0 2px 8px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 7px;
    font-size: 16px;
  }

  .brand-block .eyebrow {
    max-width: 260px;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  h1 {
    margin-top: 2px;
    font-size: 17px;
  }

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

  .nav-item {
    justify-items: center;
    min-height: 46px;
    padding: 10px 6px;
    text-align: center;
    border-radius: 8px;
  }

  .nav-item span {
    font-size: 14px;
  }

  .nav-item small,
  .sidebar-card {
    display: none;
  }

  .sidebar-export {
    padding: 8px 10px;
    min-height: 36px;
    font-size: 13px;
  }

  .sidebar-logout {
    padding: 8px 10px;
    min-height: 36px;
    font-size: 13px;
  }

  .page-header {
    display: grid;
    grid-template-columns: 1fr;
    padding: 16px 14px 12px;
  }

  h2 {
    font-size: 22px;
    line-height: 1.25;
  }

  .page-header p {
    margin-top: 6px;
    font-size: 13px;
    line-height: 1.5;
  }

  main {
    padding: 14px 12px 28px;
  }

  .entry-toolbar,
  .panel-title,
  .company-layout,
  .layout,
  .form-grid,
  .chart-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .wide-panel,
  .wide {
    grid-column: auto;
  }

  .metric {
    min-height: 104px;
    padding: 12px;
  }

  .metric strong {
    margin: 7px 0 4px;
    font-size: 18px;
  }

  .panel {
    padding: 14px;
    margin-bottom: 12px;
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.08);
  }

  h3 {
    font-size: 16px;
  }

  .filters,
  .toolbar {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .entry-toolbar {
    gap: 12px;
  }

  .form-grid {
    gap: 11px;
  }

  .form-grid button {
    width: 100%;
  }

  input,
  select {
    min-height: 42px;
    font-size: 14px;
  }

  canvas {
    height: 220px;
  }

  #monthlyTrend {
    height: 230px;
  }

  #overdueRank,
  #salesRank,
  #purchaseRank,
  #unpaidRank {
    height: 230px;
  }

  .countdown-item {
    grid-template-columns: 50px minmax(0, 1fr);
    gap: 10px;
  }

  .countdown-days {
    min-height: 50px;
  }

  .countdown-main div {
    align-items: flex-start;
  }

  .countdown-main strong,
  .countdown-main span {
    white-space: normal;
  }

  .company-list {
    max-height: 320px;
  }

  .company-item {
    align-items: flex-start;
    padding: 11px;
  }

  .company-item-meta {
    flex-basis: 82px;
  }

  .company-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .mini-metric {
    padding: 10px;
  }

  .mini-metric strong {
    font-size: 15px;
    overflow-wrap: anywhere;
  }

  .tab-button {
    flex: 1;
    min-height: 44px;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  table,
  .company-detail-panel table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tr {
    display: grid;
    gap: 7px;
    padding: 12px;
    border: 1px solid #dbe3ee;
    border-radius: 8px;
    background: #fff;
  }

  td {
    display: grid;
    grid-template-columns: minmax(82px, 31%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 0;
    border-bottom: 0;
    font-size: 13px;
    line-height: 1.55;
  }

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

  td[colspan] {
    display: block;
  }

  td[colspan]::before {
    content: none;
  }

  .status-badge {
    white-space: normal;
  }

  .table-action {
    width: 100%;
    min-height: 38px;
  }

  .empty-state {
    min-height: 130px;
  }

  .empty-row {
    min-height: 90px;
  }
}

@media (max-width: 430px) {
  .company-summary {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .login-shell {
    padding: 18px 12px;
  }

  .login-card {
    padding: 20px;
  }

  .login-heading h2 {
    font-size: 24px;
  }
}

@media (max-width: 380px) {
  .brand-block .eyebrow {
    display: none;
  }

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