:root {
  color-scheme: light;
  --sidebar: #12343b;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --accent: #d97706;
  --danger: #c43737;
  --bg: #f3f6f5;
  --surface: #ffffff;
  --surface-soft: #eef7fd;
  --text: #172321;
  --muted: #667571;
  --line: #d8e1de;
  --shadow: 0 12px 30px rgba(28, 70, 100, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  min-height: 132px;
  padding: 20px clamp(24px, 4vw, 68px);
  border-bottom: 4px solid #46c4e8;
  background: #0a4f77;
  color: #fff;
}

.brand-lockup {
  display: flex;
  min-width: 0;
  align-items: center;
}

.brand-copy {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: #8ed9ef;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 31px;
  font-weight: 700;
  letter-spacing: 0;
}

h2 {
  font-size: 17px;
  font-weight: 700;
}

main {
  width: min(1480px, calc(100% - 32px));
  margin: 24px auto 44px;
}

.workspace-app {
  min-height: 100vh;
  width: auto;
  margin: 0;
}

.workspace-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: 208px;
  padding: 24px 12px;
  background: var(--sidebar);
  color: #fff;
}

.sidebar-brand {
  display: grid;
  gap: 4px;
  padding: 0 12px 24px;
}

.sidebar-brand strong,
.sidebar-brand span {
  display: block;
}

.sidebar-brand strong {
  font-size: 20px;
}

.sidebar-brand span {
  color: #c5d6d2;
  font-size: 13px;
}

.workspace-nav {
  display: grid;
  gap: 4px;
}

.workspace-nav button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.workspace-nav button:hover,
.workspace-nav button.active {
  background: var(--primary);
}

.workspace-content {
  min-width: 0;
  margin-left: 208px;
}

.workspace-header {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.workspace-header h1 {
  font-size: 24px;
}

.workspace-header p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.workspace-heading {
  min-width: 0;
}

.workspace-meta {
  position: relative;
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.account-menu-button {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.workspace-meta .current-user {
  color: var(--muted);
}

.account-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  display: grid;
  width: 180px;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.account-menu button,
.language-switcher {
  min-height: 34px;
  border: 0;
  border-radius: 4px;
  padding: 0 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.account-menu button {
  cursor: pointer;
}

.account-menu button:hover {
  background: #edf5f3;
}

.language-switcher {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-toggle,
.workspace-overlay {
  display: none;
}

.workspace-view {
  padding: 20px 24px 36px;
}

.auth-screen {
  display: grid;
  min-height: calc(100vh - 130px);
  place-items: center;
  padding: 32px 16px;
}

.auth-card {
  display: grid;
  width: min(100%, 380px);
  gap: 16px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-card .eyebrow {
  color: var(--primary);
}

.form-status {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.form-status.error {
  color: var(--danger);
}

.topbar-actions,
.toolbar,
.panel-head {
  display: flex;
  gap: 12px;
}

.topbar-actions {
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.topbar-tools {
  display: flex;
  min-width: 0;
  max-width: 58%;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

.topbar-bottom-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.current-user {
  align-self: flex-end;
  color: #c8ebf5;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  padding-bottom: 2px;
  white-space: nowrap;
}

.language-switcher select {
  min-height: 28px;
  border: 1px solid rgba(191, 233, 247, 0.55);
  border-radius: 5px;
  padding: 0 24px 0 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.language-switcher option {
  background: #fff;
  color: var(--text);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.btn {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 700;
}

.topbar-actions .btn {
  min-height: 34px;
  padding: 0 12px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.secondary {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(191, 233, 247, 0.55);
  color: #fff;
}

.btn.secondary-light {
  background: var(--surface-soft);
  border-color: var(--line);
  color: var(--primary);
}

.btn.compact {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
}

.btn.danger {
  background: transparent;
  border-color: #e6c2c2;
  color: var(--danger);
}

.toolbar {
  flex-wrap: wrap;
  align-items: end;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.data-freshness {
  align-self: end;
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
  line-height: 34px;
}

.date-range-label {
  display: grid;
  gap: 6px;
  min-width: 230px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.date-filter-control {
  position: relative;
}

.date-range-toggle {
  position: relative;
  min-height: 38px;
  width: 230px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 34px 0 10px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-weight: 700;
}

.date-range-toggle::after {
  position: absolute;
  top: 50%;
  right: 13px;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--text);
  border-bottom: 2px solid var(--text);
  content: "";
  transform: translateY(-70%) rotate(45deg);
}

.date-range-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  left: 0;
  display: grid;
  width: 280px;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.date-range-menu input {
  min-height: 36px;
  width: 100%;
  font-size: 13px;
}

.date-range-field {
  min-width: 0;
}

label {
  display: grid;
  gap: 6px;
  min-width: 150px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  min-height: 38px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 16px;
  margin: 18px 0;
}

.kpi-card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: none;
}

.kpi-card {
  padding: 14px;
}

.kpi-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpi-card strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}

.kpi-card small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
}

.span-8 { grid-column: span 8; }
.span-7 { grid-column: span 7; }
.span-5 { grid-column: span 5; }
.span-4 { grid-column: span 4; }

.workspace-view:not([data-workspace-view="dashboard"]) .dashboard-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.workspace-view[data-workspace-view="costs"] .dashboard-grid {
  grid-template-columns: minmax(0, 1fr);
}

#dataEntryPanel {
  grid-column: 1 / -1;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel.wide {
  grid-column: span 2;
}

.panel-head {
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-head span {
  color: var(--muted);
  font-size: 13px;
}

.panel-filter {
  display: flex;
  min-width: 118px;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.panel-filter select {
  min-height: 30px;
  padding: 0 24px 0 8px;
  font-size: 12px;
}

.chart {
  width: 100%;
  height: 330px;
}

.alert-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.alert-list li {
  border-left: 4px solid var(--danger);
  padding: 10px 12px;
  background: #fff7f7;
  border-radius: 6px;
}

.alert-panel h2,
.alert-list strong {
  color: var(--danger);
}

.alert-list strong {
  display: block;
  margin-bottom: 4px;
}

.alert-list span {
  color: #8f4d4d;
  font-size: 13px;
}

.data-section {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
}

.record-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.entry-mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(320px, 100%);
  margin-bottom: 12px;
}

.entry-mode-switch button {
  min-height: 40px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.entry-mode-switch button.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.record-form [hidden] {
  display: none;
}

.fixed-cost-form,
.holiday-form,
.overtime-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.fixed-cost-form .form-wide,
.holiday-form .form-wide,
.overtime-form .form-wide,
.fixed-cost-form .form-status,
.holiday-form .form-status,
.overtime-form .form-status {
  grid-column: span 2;
}

.fixed-cost-table-wrap {
  margin-top: 16px;
}

.fixed-allocation-head {
  margin-top: 20px;
  margin-bottom: 0;
}

.fixed-cost-table {
  min-width: 720px;
  font-size: 12px;
}

.fixed-allocation-table {
  min-width: 780px;
}

.fixed-cost-table th,
.fixed-cost-table td {
  padding: 8px;
}

.icon-actions {
  display: inline-flex;
  justify-content: center;
  gap: 4px;
}

.icon-button.compact {
  width: 26px;
  height: 26px;
  font-size: 14px;
}

.danger-icon {
  color: var(--danger);
}

.holiday-list,
.overtime-list {
  display: grid;
  gap: 6px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.holiday-list li,
.overtime-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.holiday-list strong,
.overtime-list strong {
  margin-right: 8px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.holiday-list .empty,
.overtime-list .empty {
  justify-content: flex-start;
}

.import-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.file-picker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  min-width: 140px;
  padding: 0 16px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-size: 16px;
}

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.import-status {
  flex: 1 1 220px;
  color: var(--muted);
  font-size: 13px;
}

.import-status.error {
  color: var(--danger);
  font-weight: 600;
}

.record-form label {
  flex: 1 1 160px;
}

.form-action {
  align-self: end;
  flex: 1 1 160px;
}

.table-panel {
  min-width: 0;
}

.operations-table {
  width: 880px;
  min-width: 880px;
  table-layout: fixed;
  font-size: 11px;
}

.operations-table .col-date { width: 100px; }
.operations-table .col-region { width: 90px; }
.operations-table .col-source { width: 110px; }
.operations-table .col-type { width: 70px; }
.operations-table .col-orders,
.operations-table .col-shipments,
.operations-table .col-cost,
.operations-table .col-expense { width: 90px; }
.operations-table .col-people,
.operations-table .col-action { width: 80px; }

.operations-table th,
.operations-table td {
  padding: 5px 6px;
  line-height: 1.25;
}

.operations-table th {
  position: relative;
  font-size: 11px;
  font-weight: 700;
}

.operations-table td {
  overflow: hidden;
  color: #263743;
  font-size: 11px;
  font-weight: 500;
  text-overflow: ellipsis;
}

.operations-table td:nth-child(n + 5) {
  font-variant-numeric: tabular-nums;
}

.operations-table td:last-child .btn {
  min-height: 24px;
  padding: 0 7px;
  font-size: 10px;
}

.operations-table tbody tr:hover {
  background: #f6fbfe;
}

.column-resizer {
  position: absolute;
  z-index: 1;
  top: 0;
  right: -5px;
  width: 10px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
}

.column-resizer::after {
  position: absolute;
  top: 22%;
  right: 4px;
  width: 2px;
  height: 56%;
  border-radius: 2px;
  background: transparent;
  content: "";
}

.column-resizer:hover::after,
.column-resizer:active::after {
  background: var(--primary);
}

.user-dialog {
  width: min(1120px, calc(100% - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  color: var(--text);
  box-shadow: var(--shadow);
}

.user-dialog::backdrop {
  background: rgba(16, 36, 31, 0.48);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.user-form {
  display: grid;
  grid-template-columns: 1.1fr 1.1fr 0.8fr auto;
  gap: 12px;
  align-items: end;
}

.user-form .btn {
  min-width: 110px;
}

.user-table {
  min-width: 980px;
}

.edit-permissions-form {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: #f5fbfe;
}

.edit-permissions-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.edit-permissions-head strong {
  flex: 1 1 220px;
  color: var(--text);
  font-size: 14px;
}

.password-dialog {
  width: min(440px, calc(100% - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  color: var(--text);
  box-shadow: var(--shadow);
}

.password-dialog::backdrop {
  background: rgba(16, 36, 31, 0.48);
}

.password-form {
  display: grid;
  gap: 14px;
}

.reset-password-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.reset-password-form > span {
  flex: 1 1 100%;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.reset-password-form label {
  flex: 1 1 180px;
}

.permission-group {
  display: flex;
  flex-wrap: wrap;
  grid-column: 1 / -1;
  gap: 10px 16px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.permission-group legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.permission-group label {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.permission-group input {
  width: 16px;
  min-height: 16px;
  margin: 0;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th,
td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
}

td:nth-child(n + 5),
th:nth-child(n + 5) {
  text-align: right;
}

td:last-child,
th:last-child {
  text-align: center;
}

@media (max-width: 1180px) {
  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .dashboard-grid > .panel {
    grid-column: span 12;
  }
}

@media (max-width: 720px) {
  .workspace-sidebar {
    transform: translateX(-100%);
    transition: transform 180ms ease;
  }

  .workspace-content {
    margin-left: 0;
  }

  .workspace-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
  }

  .sidebar-toggle {
    display: inline-grid;
  }

  .workspace-heading {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .workspace-meta {
    grid-column: 2;
    grid-row: 1;
    width: 100%;
    flex-wrap: wrap;
    justify-self: end;
  }

  .workspace-meta .data-freshness {
    flex: 1 1 112px;
    width: auto;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .account-menu-button {
    max-width: 100%;
    min-width: 0;
  }

  .current-user {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .workspace-heading,
  .panel-head {
    overflow-wrap: anywhere;
  }

  .panel-head {
    flex-wrap: wrap;
  }

  .entry-mode-switch button,
  .import-tools > * {
    min-width: 0;
    max-width: 100%;
  }

  .import-tools .btn,
  .import-tools .file-picker {
    width: 100%;
  }

  .import-status {
    overflow-wrap: anywhere;
  }

  .workspace-view {
    padding: 16px;
  }

  .workspace-overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(18, 52, 59, 0.38);
  }

  body.sidebar-open {
    overflow: hidden;
  }

  body.sidebar-open .workspace-sidebar {
    transform: translateX(0);
  }

  body.sidebar-open .workspace-overlay {
    display: block;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    min-height: 0;
    gap: 18px;
  }

  .topbar-actions,
  .toolbar label,
  .date-range-label,
  .toolbar .btn.compact,
  .data-freshness {
    width: 100%;
  }

  .data-freshness {
    align-self: auto;
  }

  .date-range-toggle {
    width: 100%;
  }

  .topbar-tools,
  .topbar-actions,
  .topbar-bottom-row {
    max-width: none;
    align-items: stretch;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

  .topbar-bottom-row {
    width: 100%;
    flex-direction: column;
  }

  .topbar-actions .btn {
    flex: 1 1 140px;
  }

  h1 {
    font-size: 27px;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .toolbar,
  .fixed-cost-form,
  .holiday-form,
  .overtime-form {
    grid-template-columns: 1fr;
  }

  .record-form {
    display: grid;
    grid-template-columns: 1fr;
  }

  .chart {
    height: 300px;
  }

  .user-form {
    grid-template-columns: 1fr;
  }

  .fixed-cost-form .form-wide,
  .holiday-form .form-wide,
  .overtime-form .form-wide,
  .fixed-cost-form .form-status,
  .holiday-form .form-status,
  .overtime-form .form-status {
    grid-column: span 1;
  }
}
