/* StockManage design system: one stylesheet on top of Bootstrap 5.1. */
:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-muted: #f8fafb;
  --border: #e3e8ec;
  --border-strong: #cfd7de;
  --text: #15232d;
  --muted: #5f6e7a;
  --subtle: #8b98a3;
  --primary: #0e7c6b;
  --primary-hover: #0a6556;
  --primary-soft: #e7f4f1;
  --primary-ring: rgba(14, 124, 107, .16);
  --danger: #c0352b;
  --danger-soft: #fdeeec;
  --warning: #9a6200;
  --warning-soft: #fff4dc;
  --success: #15803d;
  --success-soft: #e6f6ec;
  --info: #1d5fd1;
  --info-soft: #e9f0fd;
  --sidebar-bg: #0c2726;
  --sidebar-text: #a9c2be;
  --sidebar-muted: #658683;
  --sidebar-w: 236px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 4px 12px rgba(16, 24, 40, .08);
}

html { font-size: 14.5px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft JhengHei UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }
.icon { flex: none; vertical-align: -.2em; }
.text-muted { color: var(--muted) !important; }
.text-danger { color: var(--danger) !important; }
.small, small { font-size: .86em; }
.num, .table td.text-end, .table th.text-end { font-variant-numeric: tabular-nums; }
h1, h2, h3, h4 { color: var(--text); letter-spacing: -.01em; }

/* ---------- App shell ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 1040;
  display: flex; flex-direction: column; background: var(--sidebar-bg); color: var(--sidebar-text);
}
.sidebar-brand { display: flex; align-items: center; gap: .7rem; padding: 20px 20px 14px; color: #fff; text-decoration: none; }
.sidebar-brand:hover { color: #fff; text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; flex: none;
  background: linear-gradient(140deg, #34d3b8 0%, #0e7c6b 70%);
  box-shadow: 0 4px 14px rgba(20, 184, 166, .28);
}
.brand-text strong { display: block; font-size: 15.5px; line-height: 1.2; }
.brand-text span { display: block; font-size: 11.5px; color: var(--sidebar-muted); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 12px 12px; }
.nav-group + .nav-group { margin-top: 14px; }
.nav-label { font-size: 11px; font-weight: 600; letter-spacing: .12em; color: var(--sidebar-muted); padding: 0 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: .7rem; padding: .5rem .7rem; margin: 1px 0; border-radius: 8px;
  color: var(--sidebar-text); font-size: 14px; text-decoration: none;
}
.nav-item:hover { color: #fff; background: rgba(255, 255, 255, .06); text-decoration: none; }
.nav-item.active { color: #fff; background: rgba(52, 211, 184, .14); box-shadow: inset 3px 0 0 #34d3b8; }
.sidebar-footer { display: flex; align-items: center; gap: .65rem; padding: 14px 16px; border-top: 1px solid rgba(255, 255, 255, .08); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: none; background: #1d4a46; color: #d3ece7; font-weight: 700; font-size: 13px; }
.sidebar-user { min-width: 0; flex: 1; line-height: 1.25; }
.sidebar-user strong { display: block; color: #fff; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user span { font-size: 11.5px; color: var(--sidebar-muted); }
.icon-button {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .14); background: transparent; color: var(--sidebar-text);
}
.icon-button:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.app-main { margin-left: var(--sidebar-w); min-height: 100vh; }
.content { max-width: 1480px; margin: 0 auto; padding: 30px 36px 72px; }
.topbar { display: none; }
.nav-backdrop { display: none; }

@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
  .nav-backdrop { position: fixed; inset: 0; z-index: 1035; background: rgba(12, 22, 30, .45); }
  body.nav-open .nav-backdrop { display: block; }
  .app-main { margin-left: 0; }
  .topbar {
    display: flex; align-items: center; gap: .75rem; position: sticky; top: 0; z-index: 1020;
    padding: 10px 16px; background: var(--sidebar-bg); color: #fff;
  }
  .topbar .icon-button { color: #fff; }
  .topbar-title { font-weight: 700; color: #fff; text-decoration: none; }
  .content { padding: 20px 16px 56px; }
  /* Keep Chinese names on one line; the table card scrolls sideways instead of stacking one character per line. */
  .table th, .table td { word-break: keep-all; }
}

/* ---------- Page header ---------- */
.page-back { display: inline-flex; align-items: center; gap: .35rem; margin-bottom: .55rem; color: var(--muted); font-size: 13.5px; }
.page-back:hover { color: var(--text); text-decoration: none; }
.page-header, .page-heading {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem 1.5rem; flex-wrap: wrap; margin-bottom: 22px;
}
.page-header h1, .page-heading h1 { font-size: 1.62rem; font-weight: 700; margin: 0; line-height: 1.25; }
.page-header h1 .badge { font-size: .5em; vertical-align: middle; margin-left: .4rem; }
.page-subtitle { color: var(--muted); margin: .35rem 0 0; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.section-title { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .25rem 1rem; margin: 30px 0 12px; }
.section-title h2 { font-size: 1.08rem; font-weight: 700; margin: 0; }
.section-title p { margin: 0; color: var(--muted); font-size: 13px; }

/* ---------- Cards ---------- */
.card, .work-panel, .panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.work-panel { padding: 20px 22px; }
.work-panel h2, .panel-title { font-size: 1.05rem; font-weight: 700; }
.work-panel > h2, .panel-title { margin: 0 0 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 15px 20px; border-bottom: 1px solid var(--border); }
.panel-head h2 { font-size: 1.02rem; font-weight: 700; margin: 0; }
.panel-body { padding: 18px 20px; }
.empty-panel, .empty-state {
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius);
  padding: 34px 20px; text-align: center; color: var(--muted);
}
.empty-state .icon { display: block; margin: 0 auto 8px; color: var(--subtle); }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px 24px; margin: 0; }
.meta-grid dt { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.meta-grid dd { margin: 3px 0 0; font-weight: 600; word-break: break-word; }

/* ---------- Toolbars and tabs ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: .65rem; margin-bottom: 18px;
  padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.toolbar .grow { flex: 1 1 260px; }
.toolbar .form-label { margin-bottom: .25rem; }
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: #e7ecef; }
.seg a { padding: .38rem .95rem; border-radius: 8px; color: #4a5a66; font-size: 13.5px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.seg a:hover { color: var(--text); text-decoration: none; }
.seg a.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(16, 24, 40, .1); }

/* ---------- Tables ---------- */
.table-responsive {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); margin-bottom: 1.25rem;
}
.table { margin: 0; color: var(--text); font-size: 14px; font-variant-numeric: tabular-nums; background: transparent; }
.table > :not(caption) > * > * { padding: .72rem .95rem; border-bottom-color: var(--border); vertical-align: middle; }
.table > :not(:first-child) { border-top: 0; }
.table thead th {
  background: var(--surface-muted); color: var(--muted); font-size: 12.5px; font-weight: 600; letter-spacing: .02em;
  white-space: nowrap; border-bottom: 1px solid var(--border);
}
.table tbody tr:last-child > * { border-bottom: 0; }
.table tbody tr:hover > * { background: #f7fbfa; }
.table td strong, .table td .fw-semibold { font-weight: 600; }
.table .cell-sub { display: block; font-size: 12.5px; color: var(--muted); }
.table tr.is-muted > * { color: var(--subtle); }
.table-footnote { margin: -8px 0 18px; font-size: 12.5px; color: var(--subtle); }

/* ---------- Forms ---------- */
.form-label { font-size: 13px; font-weight: 600; color: #34444f; margin-bottom: .35rem; }
.form-control, .form-select {
  min-height: 38px; font-size: 14px; color: var(--text); border-color: var(--border-strong); border-radius: var(--radius-sm);
}
.form-control::placeholder { color: #9aa6b0; }
.form-control:focus, .form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.form-control:disabled, .form-select:disabled { background: #f1f4f6; }
textarea.form-control { min-height: 74px; }
.form-check-input { border-color: #b8c3cc; }
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }
.form-check-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.form-hint { font-size: 12.5px; color: var(--muted); margin-top: .3rem; }
.form-section + .form-section { margin-top: 18px; }
.line-item, .receipt-line {
  background: var(--surface-muted); border: 1px solid var(--border) !important; border-radius: 10px !important; padding: 14px 16px !important;
}
.line-item label, .receipt-line label { font-size: 12.5px; font-weight: 600; color: #3c4b56; }
.line-item label .form-control, .line-item label .form-select { margin-top: .3rem; font-weight: 400; }
.validation-summary-errors {
  background: var(--danger-soft); border: 1px solid #f6cdc8; border-radius: 10px; padding: .7rem 1rem; margin-bottom: 1rem; color: #8f2017;
}
.validation-summary-errors ul { margin: 0; padding-left: 1.1rem; }
.validation-summary-valid { display: none; }
.field-validation-error { font-size: 12.5px; }

/* ---------- Buttons ---------- */
.btn { border-radius: var(--radius-sm); font-weight: 600; font-size: 14px; padding: .46rem .95rem; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; }
.btn-sm { font-size: 13px; padding: .3rem .7rem; border-radius: 7px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover, .btn-primary:focus, .btn-primary:active { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-primary:focus, .btn-outline-primary:focus, .btn-outline-secondary:focus, .btn-outline-danger:focus { box-shadow: 0 0 0 3px var(--primary-ring); }
.btn-outline-primary { color: var(--primary); border-color: #b5dcd4; background: #fff; }
.btn-outline-primary:hover, .btn-outline-primary:active { color: var(--primary-hover); background: var(--primary-soft); border-color: var(--primary); }
.btn-outline-secondary { color: #3b4a55; border-color: var(--border-strong); background: #fff; }
.btn-outline-secondary:hover, .btn-outline-secondary:active { color: var(--text); background: #f1f4f6; border-color: #b9c4cd; }
.btn-outline-danger { color: var(--danger); border-color: #f0c6c1; background: #fff; }
.btn-outline-danger:hover, .btn-outline-danger:active { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn-link { color: var(--primary); font-weight: 600; text-decoration: none; }
.btn-link:hover { color: var(--primary-hover); }
.btn:disabled, .btn.disabled { opacity: .55; }

/* ---------- Badges and alerts ---------- */
.badge { font-weight: 600; font-size: 12px; padding: .32em .7em; border-radius: 999px; letter-spacing: .01em; }
.text-bg-danger, .badge.bg-danger { background: var(--danger-soft) !important; color: #a8291f !important; }
.text-bg-warning, .badge.bg-warning { background: var(--warning-soft) !important; color: var(--warning) !important; }
.text-bg-success, .badge.bg-success { background: var(--success-soft) !important; color: #11652f !important; }
.text-bg-info, .badge.bg-info { background: var(--info-soft) !important; color: var(--info) !important; }
.text-bg-secondary, .badge.bg-secondary { background: #edf1f4 !important; color: #4a5965 !important; }
.alert { border-radius: 10px; padding: .8rem 1rem; font-size: 14px; border: 1px solid; }
.alert-success { background: #eefaf2; border-color: #c8ead4; color: #14532d; }
.alert-danger { background: #fef1ef; border-color: #f6cdc8; color: #8f2017; }
.alert-warning { background: #fff8e8; border-color: #f2dca4; color: #6f4600; }
.alert-info { background: var(--info-soft); border-color: #cddcfb; color: #1c3f86; }
.delta-short { color: var(--danger); font-weight: 700; }
.delta-over { color: var(--success); font-weight: 600; }

/* ---------- Danger zone ---------- */
details.danger-zone { background: var(--surface); border: 1px solid #f3d4d0; border-radius: var(--radius); padding: 14px 18px; margin-top: 26px; }
details.danger-zone > summary { cursor: pointer; font-weight: 600; color: var(--danger); list-style: none; display: flex; align-items: center; gap: .45rem; }
details.danger-zone > summary::-webkit-details-marker { display: none; }
details.danger-zone > summary::after { content: "展開"; margin-left: auto; font-size: 12.5px; font-weight: 500; color: var(--muted); }
details.danger-zone[open] > summary::after { content: "收合"; }

/* ---------- Dashboard ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; margin-bottom: 8px; }
@media (max-width: 1399.98px) { .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 767.98px) { .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } .stat-card { padding: 14px 15px; } }
.stat-card {
  display: block; padding: 18px 20px; color: inherit; text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.stat-card:hover { color: inherit; text-decoration: none; border-color: #b9ddd5; box-shadow: var(--shadow); transform: translateY(-1px); }
.stat-label { display: flex; align-items: center; gap: .45rem; color: var(--muted); font-size: 13px; font-weight: 600; }
.stat-label .icon { color: var(--primary); }
.stat-value { margin-top: 8px; font-size: 1.95rem; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-hint { margin-top: 4px; font-size: 12.5px; color: var(--subtle); }
.stat-card.is-alert .stat-value { color: var(--danger); }
.stat-card.is-alert .stat-label .icon { color: var(--danger); }
.quick-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.quick-action {
  display: flex; align-items: center; gap: .85rem; padding: 14px 16px; color: var(--text); text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); font-weight: 600;
}
.quick-action:hover { color: var(--text); text-decoration: none; border-color: #b9ddd5; box-shadow: var(--shadow); }
.quick-action small { display: block; color: var(--muted); font-weight: 400; font-size: 12.5px; }
.qa-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--primary-soft); color: var(--primary); }
.dash-columns { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 20px; }
@media (max-width: 1100px) { .dash-columns { grid-template-columns: 1fr; } }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 11px 20px; border-top: 1px solid var(--border); }
.list-plain li:first-child { border-top: 0; }
.list-plain .meta { color: var(--muted); font-size: 12.5px; }

/* ---------- Sign-in ---------- */
.auth-shell {
  min-height: 100vh; display: grid; place-items: center; padding: 32px 16px;
  background:
    radial-gradient(1100px 520px at 12% -10%, rgba(52, 211, 184, .20), transparent 60%),
    radial-gradient(900px 480px at 100% 110%, rgba(14, 124, 107, .16), transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 420px; padding: 34px 34px 28px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 20px 50px rgba(16, 24, 40, .10);
}
.auth-brand { display: flex; align-items: center; gap: .75rem; margin-bottom: 26px; }
.auth-brand strong { display: block; font-size: 16px; }
.auth-brand span { display: block; font-size: 12.5px; color: var(--muted); }
.auth-card h1 { font-size: 1.45rem; font-weight: 700; margin: 0 0 4px; }
.auth-card .form-control { min-height: 42px; }
.input-icon { position: relative; }
.input-icon > .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--subtle); pointer-events: none; }
.input-icon > .form-control { padding-left: 38px; }
.input-icon > .form-control.has-reveal { padding-right: 42px; }
.input-icon > .reveal {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--subtle); padding: 6px; border-radius: 6px;
}
.input-icon > .reveal:hover { color: var(--text); background: #f1f4f6; }
.auth-options { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem 1rem; margin: 4px 0 18px; font-size: 13.5px; }
.auth-options .form-check-label { color: #3c4b56; }
.auth-note { margin: 16px 0 0; font-size: 12.5px; color: var(--subtle); text-align: center; }
.auth-card .btn-primary { min-height: 44px; font-size: 15px; }

/* ---------- Misc ---------- */
.sticky-xl-top { top: 20px; }
pre { font-size: 12.5px; border-radius: 10px; }
iframe { border-radius: 10px; }
.danger-text { color: var(--danger); }
@media (max-width: 575.98px) {
  .page-header h1, .page-heading h1 { font-size: 1.35rem; }
  .work-panel { padding: 16px; }
}

/* A table inside a card (e.g. the picking list in a shipment form) needs no second shadow. */
.work-panel .table-responsive { box-shadow: none; }
