:root {
  --bg: #f7f9f7;
  --surface: #ffffff;
  --surface-soft: #eef7f4;
  --ink: #17201d;
  --muted: #64716d;
  --line: #dce5e1;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --blue: #2563eb;
  --amber: #b7791f;
  --red: #c2410c;
  --green: #15803d;
  --shadow: 0 12px 32px rgba(20, 35, 31, 0.11);
  --radius: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.10), transparent 36rem),
    linear-gradient(315deg, rgba(37, 99, 235, 0.07), transparent 34rem),
    var(--bg);
  color: var(--ink);
}

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

button {
  border: 0;
  cursor: pointer;
}

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

img {
  display: block;
  max-width: 100%;
}

noscript {
  display: block;
  padding: 1rem;
  background: #fff7ed;
  color: #9a3412;
}

.toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: calc(1rem + var(--safe-bottom));
  transform: translate(-50%, 1rem);
  max-width: min(28rem, calc(100vw - 2rem));
  padding: 0.8rem 1rem;
  border-radius: var(--radius);
  background: #17201d;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.auth-view {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: calc(1.5rem + var(--safe-top)) 1rem calc(1.5rem + var(--safe-bottom));
}

.auth-panel {
  width: min(100%, 28rem);
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.brand-icon {
  flex: 0 0 auto;
  border-radius: 8px;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.22);
}

.eyebrow {
  margin: 0 0 0.2rem;
  color: var(--primary);
  font-size: 0.77rem;
  font-weight: 800;
  letter-spacing: 0;
}

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

.brand-lockup h1,
.title-block h1 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2rem);
  line-height: 1.12;
}

.auth-form {
  display: grid;
  gap: 0.9rem;
}

label {
  display: grid;
  gap: 0.38rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 0.72rem 0.78rem;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

textarea {
  min-height: 5.5rem;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.primary,
.secondary,
.danger,
.ghost,
.icon-btn {
  min-height: 2.75rem;
  border-radius: var(--radius);
  padding: 0.72rem 0.92rem;
  font-weight: 800;
  line-height: 1;
}

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

.secondary {
  background: #e6f3f0;
  color: #0b5f58;
}

.danger {
  background: #fff1ed;
  color: #b43109;
}

.ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.full {
  width: 100%;
}

.fine-print {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.55;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(1rem + var(--safe-bottom));
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: calc(0.75rem + var(--safe-top)) 1rem 0.75rem;
  border-bottom: 1px solid rgba(220, 229, 225, 0.82);
  background: rgba(247, 249, 247, 0.88);
  backdrop-filter: blur(16px);
}

.title-block {
  min-width: 0;
}

.title-block h1 {
  overflow-wrap: anywhere;
}

.secure-state {
  display: inline-flex;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.icon-btn {
  width: 2.75rem;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 1.35rem;
}

.tabbar {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding: 0.75rem 1rem;
  scrollbar-width: none;
}

.tabbar::-webkit-scrollbar {
  display: none;
}

.tabbar button {
  flex: 0 0 auto;
  min-width: 4.25rem;
  min-height: 2.45rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  font-weight: 800;
}

.tabbar button.active {
  border-color: rgba(15, 118, 110, 0.28);
  background: var(--primary);
  color: #fff;
}

.screen {
  width: min(76rem, 100%);
  min-width: 0;
  margin: 0 auto;
  padding: 0 1rem 1rem;
}

.screen-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  margin: 0.25rem 0 1rem;
}

.screen-header h2 {
  margin: 0;
  font-size: clamp(1.25rem, 3vw, 1.8rem);
}

.screen-header p {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
}

.toolbar > * {
  flex: 0 0 auto;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.metric {
  min-height: 7.1rem;
  padding: 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric strong {
  display: block;
  margin: 0.2rem 0 0.45rem;
  font-size: clamp(1.22rem, 5vw, 1.95rem);
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.metric span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.metric small {
  color: var(--muted);
}

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

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

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

.panel {
  min-width: 0;
  margin-top: 0.85rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
}

.panel h3 {
  margin-bottom: 0.8rem;
  font-size: 1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.form-grid > *,
.split > * {
  min-width: 0;
}

.form-grid .span-2 {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
}

.data-actions {
  margin-top: 1rem;
}

.hint-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  padding: 0.38rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 42rem;
}

th,
td {
  padding: 0.72rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
  white-space: nowrap;
}

td {
  font-size: 0.92rem;
}

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

.num {
  text-align: right;
  white-space: nowrap;
}

.record-list {
  display: none;
}

.record-card {
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.record-card + .record-card {
  margin-top: 0.7rem;
}

.record-card-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: start;
}

.record-card-head strong,
.record-card-head b {
  display: block;
  overflow-wrap: anywhere;
}

.record-card-head span {
  display: block;
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.record-card-head .record-customer {
  display: inline-flex;
  max-width: 100%;
  margin-top: 0.45rem;
  padding: 0.34rem 0.52rem;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: var(--radius);
  background: #e6f3f0;
  color: #0b5f58;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.record-card-head b {
  color: var(--green);
  text-align: right;
}

.record-card-head b.bad {
  color: var(--red);
}

.record-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin: 0.8rem 0 0;
}

.record-grid div {
  min-width: 0;
  padding: 0.6rem;
  border-radius: var(--radius);
  background: #f6faf8;
}

.record-grid dt {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 900;
}

.record-grid dd {
  margin: 0.18rem 0 0;
  font-weight: 850;
  overflow-wrap: anywhere;
}

.record-meta {
  display: grid;
  gap: 0.38rem;
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.muted {
  color: var(--muted);
}

.empty {
  padding: 1.25rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  text-align: center;
}

.chart {
  display: grid;
  grid-template-columns: repeat(12, minmax(2.7rem, 1fr));
  gap: 0.45rem;
  align-items: end;
  min-height: 13rem;
  overflow-x: auto;
  padding: 0.5rem 0.1rem 0;
}

.bar {
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 12rem;
  gap: 0.35rem;
}

.bar-svg {
  display: block;
  width: 100%;
  min-height: 9rem;
}

.bar-track {
  fill: #edf2f0;
}

.bar-revenue-svg {
  fill: var(--blue);
}

.bar-profit-svg {
  fill: var(--green);
  opacity: 0.82;
}

.bar label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(18rem, 0.65fr);
  gap: 0.85rem;
  align-items: start;
}

.product-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 0.75rem;
}

.product-card {
  min-height: 12rem;
  padding: 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.product-card h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.product-card dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 0.8rem;
  margin: 0.75rem 0;
}

.product-card dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.product-card dd {
  margin: 0;
  text-align: right;
  font-weight: 800;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.compact-btn {
  min-height: 2.2rem;
  padding: 0.45rem 0.62rem;
  border-radius: var(--radius);
  background: #f1f5f4;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 850;
}

.compact-btn.dangerish {
  background: #fff1ed;
  color: #b43109;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.status-dot::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--green);
}

.status-dot.off::before {
  background: var(--muted);
}

@media (max-width: 760px) {
  .app-header {
    align-items: start;
  }

  .screen-header {
    display: grid;
    align-items: start;
  }

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

  table {
    min-width: 34rem;
  }

  .record-view .table-wrap {
    display: none;
  }

  .record-list {
    display: block;
  }

  .toolbar select,
  .toolbar button,
  .form-actions button {
    flex: 1 1 9rem;
  }

  .panel {
    padding: 0.85rem;
  }

  .metric {
    min-height: 6.4rem;
  }
}

@media (display-mode: standalone) {
  body {
    user-select: none;
    -webkit-user-select: none;
  }

  input,
  textarea {
    user-select: text;
    -webkit-user-select: text;
  }
}
