:root {
  --bg: #f3f5f8;
  --bg-strong: #e9eef5;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --surface-soft: #f1f5f9;
  --border: #dde4ee;
  --border-strong: #bcc8d6;
  --text: #132238;
  --text-secondary: #41556f;
  --text-muted: #708197;
  --primary: #1d4f91;
  --primary-hover: #153c6f;
  --primary-soft: #e9f1fb;
  --success: #1f7a4b;
  --success-soft: #dff3e8;
  --warning: #9a6700;
  --warning-soft: #fff3d6;
  --danger: #c2413a;
  --danger-soft: #fde8e7;
  --shadow-sm: 0 10px 24px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 18px 40px rgba(15, 23, 42, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 13px;
  line-height: 1.6;
  background:
    radial-gradient(circle at top left, rgba(29, 79, 145, 0.08), transparent 28%),
    linear-gradient(180deg, #f7f9fc 0%, var(--bg) 100%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

.hidden {
  display: none !important;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 20px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ===== Login ===== */
.login-screen {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at top right, rgba(29, 79, 145, 0.18), transparent 28%),
    linear-gradient(160deg, #eef3f8 0%, #f7f9fc 55%, #edf2f7 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.login-screen.hidden {
  display: none;
}

body.boot-authenticated .login-screen {
  display: none;
}

.login-card {
  width: min(420px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid rgba(188, 200, 214, 0.8);
  border-radius: var(--radius-lg);
  padding: 36px;
  display: grid;
  gap: 16px;
  box-shadow: var(--shadow-md);
}

.login-card h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
  font-weight: 700;
}

.login-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

.login-card label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.login-card input {
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.16s, box-shadow 0.16s, background 0.16s;
}

.login-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(29, 79, 145, 0.08);
}

.login-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 12px;
}

.login-notice {
  background: rgba(46, 139, 87, 0.08);
  border: 1px solid rgba(46, 139, 87, 0.35);
  border-radius: 10px;
  padding: 12px 14px;
  display: grid;
  gap: 6px;
}

.login-notice.hidden {
  display: none;
}

.login-notice .login-notice-label {
  font-size: 11px;
  color: #3c7f5b;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.login-notice .login-notice-code {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.18em;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  color: #1d4f91;
  cursor: pointer;
  user-select: all;
}

.login-notice .login-notice-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.code-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.code-row input {
  flex: 1;
  min-width: 0;
}

.code-row button {
  flex: 0 0 auto;
  min-width: 108px;
}

.code-row button:disabled {
  background: var(--surface-alt);
  color: var(--text-muted);
  border-color: var(--border);
  cursor: not-allowed;
}

/* ===== Layout ===== */
.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
  transition: grid-template-columns 0.2s ease;
}

.layout.sidebar-collapsed {
  grid-template-columns: 88px 1fr;
}

.sidebar {
  background: linear-gradient(180deg, #10243d 0%, #153050 100%);
  color: #dbe5f2;
  padding: 20px 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 16px;
  border-bottom: 1px solid rgba(219, 229, 242, 0.14);
  line-height: 1.4;
  font-size: 15px;
  font-weight: 600;
  color: #f8fbff;
}

.brand-copy {
  min-width: 0;
  flex: 1;
}

.brand small {
  display: block;
  margin-top: 2px;
  color: rgba(219, 229, 242, 0.72);
  font-size: 11px;
  font-weight: 400;
}

.brand-mark {
  display: inline-flex;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: linear-gradient(135deg, #2d65af 0%, #183b68 100%);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.sidebar-toggle {
  width: 32px;
  min-width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.08);
  color: #f8fbff;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.24);
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu-group {
  display: grid;
  gap: 4px;
}

.menu-item-label {
  display: inline-block;
}

.menu-item {
  border: 0;
  background: transparent;
  color: rgba(219, 229, 242, 0.8);
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.16s, color 0.16s, transform 0.16s;
}

.menu-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  transform: translateX(2px);
}

.menu-item.active {
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.08));
  color: #ffffff;
  font-weight: 500;
}

.layout.sidebar-collapsed .sidebar {
  padding-left: 8px;
  padding-right: 8px;
}

.layout.sidebar-collapsed .brand {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
  gap: 8px;
}

.layout.sidebar-collapsed .brand-copy,
.layout.sidebar-collapsed .menu-item-label {
  display: none;
}

.layout.sidebar-collapsed .menu-item {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 10px 6px;
}

.layout.sidebar-collapsed .menu-item::before {
  content: attr(title);
  font-size: 11px;
  line-height: 1.2;
  text-align: center;
}

.layout.sidebar-collapsed .menu-item:hover {
  transform: none;
}

/* ===== Content ===== */
.content {
  padding: 28px 32px 40px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding: 0 0 18px;
  border-bottom: 1px solid rgba(188, 200, 214, 0.7);
}

.topbar h1 {
  margin: 4px 0 0;
  font-size: 28px;
  line-height: 1.15;
  font-weight: 700;
  color: var(--text);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.current-user {
  color: var(--text-secondary);
  font-size: 12px;
  padding: 9px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(188, 200, 214, 0.65);
}

.section {
  display: none;
}

.section.active {
  display: block;
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 0 8px;
}

.tab {
  border: 0;
  background: transparent;
  padding: 12px 16px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.12s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 500;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ===== Cards / Panels ===== */
.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid rgba(221, 228, 238, 0.92);
  border-radius: 18px;
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.stat-value {
  font-size: 30px;
  font-weight: 700;
  color: var(--text);
  margin-top: 10px;
  line-height: 1.2;
}

.grid-two {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid rgba(221, 228, 238, 0.92);
  border-radius: 18px;
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.panel:last-child {
  margin-bottom: 0;
}

.panel-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(221, 228, 238, 0.86);
}

.panel-title.with-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-subtitle {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}

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

.section-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.section-subtitle {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== Tables ===== */
.simple-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.simple-table thead th {
  background: #f6f9fc;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 12px;
  text-align: left;
  padding: 11px 12px;
  border-top: 1px solid rgba(221, 228, 238, 0.92);
  border-bottom: 1px solid rgba(221, 228, 238, 0.92);
  white-space: nowrap;
}

.simple-table tbody td {
  padding: 12px;
  border-bottom: 1px solid rgba(221, 228, 238, 0.92);
  color: var(--text);
  vertical-align: middle;
}

.simple-table tbody tr:hover td {
  background: #fbfdff;
}

.simple-table tbody tr:last-child td {
  border-bottom: 0;
}

.simple-table a {
  color: var(--primary);
  text-decoration: none;
}

.simple-table a:hover {
  text-decoration: underline;
}

/* ===== Forms ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px 16px;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.input-label {
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.form-grid input,
.form-grid select {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  font-size: 13px;
  color: var(--text);
  transition: border-color 0.16s, box-shadow 0.16s, background 0.16s;
}

.form-grid input[type="file"] {
  height: auto;
  padding: 8px 10px;
}

.form-grid input:focus,
.form-grid select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(29, 79, 145, 0.08);
}

.form-grid input[readonly] {
  background: var(--surface-soft);
  color: var(--text-secondary);
}

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

.permission-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-alt);
}

.permission-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid rgba(221, 228, 238, 0.92);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-secondary);
}

.permission-item input[type="checkbox"] {
  margin: 0;
}

.permission-item span {
  font-size: 12px;
  line-height: 1.4;
}

/* ===== Buttons ===== */
button {
  font-family: inherit;
  font-size: 13px;
}

button.primary,
button.secondary,
button.danger {
  height: 36px;
  padding: 0 16px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.16s, border-color 0.16s, color 0.16s, box-shadow 0.16s, transform 0.16s;
}

button.primary {
  background: linear-gradient(180deg, #24589e 0%, var(--primary) 100%);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 8px 18px rgba(29, 79, 145, 0.18);
}

button.primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  transform: translateY(-1px);
}

button.secondary {
  background: var(--surface);
  color: var(--text-secondary);
  border-color: var(--border-strong);
}

button.secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: #fdfefe;
}

button.danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--border-strong);
}

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

.simple-table button.primary,
.simple-table button.secondary,
.simple-table button.danger {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

/* ===== Tags ===== */
.tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  line-height: 16px;
  white-space: nowrap;
}

.tag.blue {
  background: var(--primary-soft);
  color: var(--primary);
}

.tag.green {
  background: var(--success-soft);
  color: var(--success);
}

.tag.orange {
  background: var(--warning-soft);
  color: var(--warning);
}

.tag.red {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 18px;
  right: 22px;
  z-index: 80;
  display: none;
  max-width: min(420px, calc(100vw - 32px));
  color: #fff;
  font-size: 12px;
  line-height: 1.5;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(19, 34, 56, 0.92);
  border: 1px solid rgba(19, 34, 56, 0.96);
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.22);
}

.toast.show {
  display: block;
}

/* ===== Upload inline ===== */
.upload-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.upload-inline input[type="file"] {
  font-size: 12px;
}

/* ===== Empty / Notes ===== */
.empty {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 24px 0;
}

.notes {
  color: var(--text-muted);
  font-size: 13px;
  padding-left: 20px;
  margin: 0;
}

.notes li {
  margin-bottom: 4px;
}

/* ===== Subtasks ===== */
.subtasks {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.subtask-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--surface);
}

.subtask-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.subtask-head strong {
  font-size: 13px;
  font-weight: 600;
}

.subtask-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

/* ===== Filter / Actions row ===== */
.filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-row input,
.filter-row select {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 12px;
  color: var(--text);
  font-family: inherit;
}

.filter-row input:focus,
.filter-row select:focus {
  outline: none;
  border-color: var(--primary);
}

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

/* ===== Task Allocation ===== */
.task-form-block,
.task-batch-panel {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid rgba(221, 228, 238, 0.92);
  border-radius: 14px;
  background: linear-gradient(180deg, #fbfdff 0%, #f7fafe 100%);
}

.task-batch-panel {
  margin-top: 16px;
}

.allocation-layout .content {
  padding-bottom: 48px;
}

.allocation-hero {
  margin-bottom: 16px;
}

.allocation-hero-panel {
  display: grid;
  gap: 16px;
  background: linear-gradient(135deg, #f9fbfe 0%, #eef4fb 100%);
}

.allocation-hero-copy {
  display: grid;
  gap: 6px;
}

.allocation-toolbar-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.allocation-toolbar-card {
  display: grid;
  gap: 14px;
  align-content: start;
}

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

.allocation-control-grid label {
  display: grid;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 12px;
}

.allocation-control-full {
  grid-column: 1 / -1;
}

.allocation-control-grid input,
.allocation-control-grid select {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.allocation-control-grid input:focus,
.allocation-control-grid select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(29, 79, 145, 0.08);
}

.allocation-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.allocation-preview-btn {
  width: 100%;
  margin-bottom: 10px;
}

.allocation-submit-card {
  background: linear-gradient(180deg, #fbfdff 0%, #f3f7fc 100%);
}

.allocation-submit-btn {
  width: 100%;
  height: 42px;
}

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

.preview-summary {
  margin-top: -2px;
}

.preview-table-wrap {
  overflow-x: auto;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(19, 34, 56, 0.38);
}

.modal-card {
  width: min(1180px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid rgba(221, 228, 238, 0.92);
  border-radius: 20px;
  box-shadow: var(--shadow-md);
  padding: 20px 22px;
}

.preview-modal-card {
  display: grid;
  gap: 14px;
}

.preview-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.preview-status.ok {
  color: var(--success);
  background: var(--success-soft);
}

.preview-status.error {
  color: var(--danger);
  background: var(--danger-soft);
}

.preview-errors {
  color: var(--danger);
  font-size: 12px;
}

.panel-title.small {
  font-size: 14px;
  margin-bottom: 0;
}

.task-form-toolbar {
  display: flex;
  gap: 8px;
  align-items: end;
  flex-wrap: wrap;
}

.task-form-toolbar label {
  display: grid;
  gap: 6px;
  min-width: 180px;
  color: var(--text-secondary);
  font-size: 12px;
}

.task-form-toolbar input,
.task-form-toolbar select,
.allocation-input {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}

.task-form-toolbar input,
.task-form-toolbar select {
  height: 36px;
  padding: 0 12px;
}

.allocation-summary {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.allocation-chip {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.allocation-chip.ok {
  background: var(--success-soft);
  color: var(--success);
  border-color: transparent;
}

.allocation-chip.warn {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: transparent;
}

.allocation-chip.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}

.allocation-board {
  overflow-x: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.allocation-table td strong {
  font-size: 13px;
}

.allocation-input {
  width: 120px;
  height: 32px;
  padding: 0 10px;
}

.matrix-table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
}

.matrix-table th,
.matrix-table td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  padding: 8px 6px;
  border-right: 1px solid rgba(221, 228, 238, 0.92);
  border-bottom: 1px solid rgba(221, 228, 238, 0.92);
  vertical-align: middle;
}

.matrix-table th:first-child,
.matrix-table td:first-child {
  border-left: 1px solid rgba(221, 228, 238, 0.92);
}

.matrix-table input {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
}

.matrix-table input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(29, 79, 145, 0.08);
}

.matrix-lead-head,
.matrix-summary-head {
  vertical-align: middle !important;
  font-size: 12px;
  font-weight: 600;
}

.matrix-header-cell {
  padding: 10px 6px;
}

.matrix-value-cell.selected {
  background: #dbeafe;
  box-shadow: inset 0 0 0 2px #2563eb;
}

.matrix-value-cell.selected .matrix-cell-input {
  background: transparent;
}

.matrix-table .matrix-total-input {
  width: 88px;
}

.matrix-customer-cell {
  background: #fcfdff;
}

.matrix-customer-select {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
}

.matrix-customer-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(29, 79, 145, 0.08);
}

.matrix-table .matrix-date-input {
  width: 96px;
}

.matrix-column-head {
  display: grid;
  gap: 6px;
  min-width: 0;
  text-align: center;
  align-items: stretch;
}

.matrix-column-caption {
  display: none;
}

.matrix-merchant-select {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 11px;
  font-family: inherit;
}

.matrix-column-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.matrix-column-actions .secondary,
.matrix-column-actions .danger {
  width: 100%;
  height: 28px;
  padding: 0;
  font-size: 11px;
  min-width: 0;
}

.matrix-actions-cell {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 8px 6px;
}

.matrix-actions-cell .secondary,
.matrix-actions-cell .danger {
  width: 100%;
  height: 28px;
  padding: 0;
  min-width: 0;
  font-size: 11px;
}

.matrix-total-cell,
.matrix-date-cell {
  background: #fcfdff;
}

.matrix-summary-cell {
  padding-top: 16px !important;
  font-weight: 600;
  vertical-align: middle !important;
  font-size: 12px;
}

.matrix-allocated-cell,
.matrix-remaining-cell,
.matrix-meta-row th,
.matrix-total-row td {
  white-space: nowrap;
}

.matrix-table .matrix-column-left-btn,
.matrix-table .matrix-column-right-btn {
  display: none;
}

.matrix-ok {
  color: var(--success);
  font-weight: 600;
}

.matrix-bad {
  color: var(--danger);
  font-weight: 600;
}

.matrix-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fbfe;
  box-shadow: inset 0 -1px 0 rgba(221, 228, 238, 0.92);
}

.matrix-meta-row th {
  background: #edf4fb;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 12px;
}

.matrix-total-row td {
  position: sticky;
  bottom: 0;
  z-index: 1;
  background: #f7fafc;
  font-weight: 600;
  vertical-align: middle;
}

.matrix-sticky-col {
  position: sticky;
  left: 0;
  z-index: 3;
  background: inherit;
  vertical-align: middle !important;
}

.matrix-sticky-action {
  position: sticky;
  right: 0;
  z-index: 3;
  background: inherit;
}

.matrix-index-cell {
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 60px;
  background: #f8fbfe;
}

.helper-text {
  color: var(--text-muted);
  font-size: 12px;
}

/* ===== Mobile Workbench ===== */
.mobile-shell {
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, rgba(29, 79, 145, 0.12), transparent 32%),
    linear-gradient(180deg, #f7f9fc 0%, #eef3f8 100%);
}

.mobile-page {
  max-width: 460px;
  margin: 0 auto;
  padding: 20px 16px 32px;
}

.mobile-stack {
  display: grid;
  gap: 14px;
}

.mobile-card {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(221, 228, 238, 0.92);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.mobile-hero {
  background: linear-gradient(135deg, #183b68 0%, #24589e 100%);
  color: #fff;
}

.mobile-hero .eyebrow,
.mobile-hero .mobile-muted {
  color: rgba(255, 255, 255, 0.76);
}

.mobile-title {
  margin: 6px 0 0;
  font-size: 22px;
  line-height: 1.2;
  font-weight: 700;
}

.mobile-subtitle {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.mobile-muted {
  font-size: 12px;
  color: var(--text-muted);
}

.mobile-amount {
  margin-top: 10px;
  font-size: 34px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0.01em;
}

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

.mobile-grid.three {
  grid-template-columns: repeat(3, 1fr);
}

.mobile-stat {
  padding: 14px 12px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid rgba(221, 228, 238, 0.92);
  text-align: center;
}

.mobile-stat.active {
  border-color: rgba(29, 79, 145, 0.5);
  background: var(--primary-soft);
}

.mobile-stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.mobile-stat-label {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.mobile-qr {
  width: 100%;
  max-width: 320px;
  border-radius: 16px;
  border: 1px solid rgba(221, 228, 238, 0.92);
}

.mobile-center {
  text-align: center;
}

.mobile-upload-input {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  background: var(--surface-alt);
}

.mobile-task-card {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid rgba(221, 228, 238, 0.92);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
}

.mobile-task-main {
  min-width: 0;
}

.mobile-task-name {
  font-size: 14px;
  color: var(--text-secondary);
}

.mobile-task-amount {
  margin-top: 4px;
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

.mobile-task-time {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.mobile-task-side {
  text-align: right;
}

.mobile-arrow {
  margin-top: 8px;
  font-size: 18px;
  color: var(--text-muted);
}

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

.mobile-list.hidden {
  display: none !important;
}

.mobile-toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(19, 34, 56, 0.86);
  color: #fff;
  font-size: 13px;
  z-index: 99;
}

.mobile-overlay {
  position: fixed;
  inset: 0;
  background: rgba(19, 34, 56, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.mobile-overlay-box {
  width: min(360px, 100%);
  background: #fff;
  border-radius: 20px;
  padding: 28px 22px;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.mobile-success-icon {
  display: inline-flex;
  width: 64px;
  height: 64px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--success);
  font-size: 30px;
  font-weight: 700;
}

/* ===== Responsive ===== */
@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .layout.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    padding: 12px;
    border-right: 0;
  }

  .brand {
    border-bottom: 0;
    padding-bottom: 8px;
  }

  .layout.sidebar-collapsed .brand-copy,
  .layout.sidebar-collapsed .menu-item-label {
    display: initial;
  }

  .layout.sidebar-collapsed .menu-item {
    display: block;
    min-height: auto;
    padding: 10px 12px;
  }

  .layout.sidebar-collapsed .menu-item::before {
    content: none;
  }

  .menu {
    flex-direction: row;
    overflow-x: auto;
    gap: 8px;
  }

  .menu-group {
    display: flex;
    gap: 8px;
    align-items: center;
  }

  .menu-item {
    white-space: nowrap;
  }

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

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

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

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

  .modal-card {
    width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
    padding: 16px;
  }

  .task-form-toolbar label,
  .allocation-input {
    width: 100%;
  }
}
