:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #edf4f5;
  --ink: #182126;
  --muted: #5f6f75;
  --line: #d8e0dd;
  --primary: #155e75;
  --primary-strong: #0f4454;
  --accent: #c95f2e;
  --success: #2f7d4f;
  --warning: #b7791f;
  --danger: #b42318;
  --shadow: 0 18px 40px rgba(26, 43, 48, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

[hidden] {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 24px 48px;
}

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

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

.login-card {
  width: min(460px, 100%);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin-bottom: 20px;
}

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

.user-box {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.user-box span {
  color: var(--muted);
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 15px;
  font-weight: 800;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(32px, 5vw, 54px);
}

h2 {
  font-size: 22px;
}

.top-actions,
.panel-heading,
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

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

.metric,
.panel,
.data-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 34px;
}

.metric.warning strong {
  color: var(--warning);
}

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

.panel,
.data-section {
  padding: 20px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  min-width: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segment {
  min-height: 44px;
  border-radius: 0;
  background: var(--surface-soft);
  color: var(--muted);
}

.segment.active {
  background: var(--primary);
  color: white;
}

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

.form-grid.compact {
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 0 14px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(21, 94, 117, 0.15);
}

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

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 0.9fr);
  gap: 18px;
  margin-top: 16px;
}

.member-list-wrap {
  min-width: 0;
}

.member-list-wrap h3 {
  margin: 0 0 12px;
  font-size: 18px;
}

.member-list {
  display: grid;
  gap: 8px;
}

.member-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 54px;
  padding: 10px 12px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.member-row strong,
.member-row span {
  display: block;
}

.member-row span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

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

.role-pill {
  display: inline-grid;
  place-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: #e7f6ed;
  color: var(--success);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.role-pill.admin {
  background: #e5f2f7;
  color: var(--primary);
}

.edit-panel {
  margin-top: 16px;
  padding: 16px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.edit-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.edit-heading strong {
  font-size: 18px;
}

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

.primary-button:active {
  background: var(--primary-strong);
}

.secondary-button {
  background: var(--accent);
  color: white;
}

.ghost-button,
.danger-button {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
}

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

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

.danger-button {
  background: #fff5f3;
  color: var(--danger);
}

.data-section {
  margin-top: 18px;
}

.admin-view {
  margin-top: 0;
}

.search-box {
  width: min(360px, 50%);
}

.table-wrap {
  overflow-x: auto;
  margin-top: 16px;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 8px;
  min-width: 860px;
}

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

tbody tr {
  background: white;
}

tbody td:first-child {
  border-left: 1px solid transparent;
  border-radius: 8px 0 0 8px;
}

tbody td:last-child {
  border-right: 1px solid transparent;
  border-radius: 0 8px 8px 0;
}

tbody tr.inventory-alert td {
  background: #fff3f0;
  border-top: 2px solid #d92d20;
  border-bottom: 2px solid #d92d20;
}

tbody tr.inventory-alert td:first-child {
  border-left-color: #d92d20;
}

tbody tr.inventory-alert td:last-child {
  border-right-color: #d92d20;
}

tbody tr.inventory-alert.empty td {
  background: #ffebe7;
  border-top-color: var(--danger);
  border-bottom-color: var(--danger);
}

tbody tr.inventory-alert.empty td:first-child {
  border-left-color: var(--danger);
}

tbody tr.inventory-alert.empty td:last-child {
  border-right-color: var(--danger);
}

th {
  color: var(--muted);
  font-size: 13px;
}

td {
  font-size: 16px;
  font-weight: 650;
}

.stock-count {
  font-size: 22px;
}

.update-user,
.update-time {
  display: block;
}

.update-time {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  background: #e7f6ed;
  color: var(--success);
  font-size: 14px;
  font-weight: 800;
}

.status-pill.low {
  background: #fff5df;
  color: var(--warning);
}

.status-pill.empty {
  background: #fff0ed;
  color: var(--danger);
}

.movement-table {
  min-width: 860px;
}

.movement-type {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  background: #e7f6ed;
  color: var(--success);
  font-size: 14px;
  font-weight: 800;
}

.movement-type.out {
  background: #fff2e8;
  color: var(--accent);
}

.empty-cell {
  height: 90px;
  text-align: center;
  color: var(--muted);
}

.log-list {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.log-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 0 14px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.log-row span,
.empty-log {
  color: var(--muted);
  font-weight: 700;
}

.empty-log {
  min-height: 56px;
  display: grid;
  place-items: center;
}

.action-button {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: white;
  color: var(--primary);
  font-size: 14px;
}

.modal-dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

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

.modal-card {
  display: grid;
  gap: 14px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.modal-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.modal-title h2 {
  margin: 4px 0 0;
  font-size: 22px;
}

.icon-button {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  background: white;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

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

.audit-entry {
  display: grid;
  gap: 5px;
  padding: 12px 14px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.audit-entry strong {
  font-size: 15px;
}

.audit-entry span {
  color: var(--muted);
  font-weight: 700;
}

@media (max-width: 900px) {
  .topbar,
  .work-area,
  .section-title {
    align-items: stretch;
    flex-direction: column;
  }

  .user-box {
    justify-content: space-between;
  }

  .work-area {
    display: flex;
  }

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

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

  .search-box {
    width: 100%;
  }

  .modal-actions {
    flex-direction: column-reverse;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: max(16px, env(safe-area-inset-top)) 14px 32px;
  }

  .user-box {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .user-box span {
    grid-column: 1 / -1;
  }

  .top-actions,
  .form-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

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