/* ERP 核心平台 — 滿版細邊框卡片（對齊曼妮風：#dde2e6 邊框、4px 圓角、主色 #1a5276） */

:root {
  --c-bg: #f0f2f4;
  --c-surface: #ffffff;
  --c-border: #dde2e6;
  --c-border-strong: #cfd6db;
  --c-text: #333333;
  --c-muted: #888888;
  --c-heading: #555555;
  --c-primary: #1a5276;
  --c-primary-dark: #154360;
  --c-cyan: #0e8a9a;
  --c-danger: #e74c3c;
  --c-success: #27ae60;
  --c-warning: #c87f0a;
  --c-info: #3498db;
  --c-input: #f0f2f4;
  --radius: 4px;
  --sidebar-w: 220px;
  --topbar-h: 52px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

a { color: var(--c-cyan); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------- 版面 */
.layout {
  display: flex;
  min-height: 100vh;
  background: var(--c-bg);
}

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: #1a5276;
  color: #d5e4ee;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}

.sidebar .brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 16px 12px;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, .12);
  flex: 0 0 auto;
}
.sidebar .brand:hover { text-decoration: none; }
.sidebar .brand-name { font-size: 16px; font-weight: 700; letter-spacing: .02em; }
.sidebar .brand-sub { font-size: 11px; color: #9ec3d6; font-weight: 400; }

.sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 0 24px;
}
.sidebar-nav::-webkit-scrollbar { width: 8px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 4px; }

.menu-group { padding: 4px 0 8px; border: 0; }
.menu-group > summary,
.menu-group > .menu-group-label {
  list-style: none;
  cursor: pointer;
  padding: 8px 16px 4px;
  font-size: 11px;
  letter-spacing: .12em;
  color: #8fb3c7;
  font-weight: 700;
  user-select: none;
}
.menu-group > summary::-webkit-details-marker { display: none; }
.menu-group > summary::after {
  content: "";
  float: right;
  margin-top: 5px;
  border: 4px solid transparent;
  border-top-color: #8fb3c7;
}
.menu-group[open] > summary::after {
  margin-top: 2px;
  border-top-color: transparent;
  border-bottom-color: #8fb3c7;
}

.menu-group a {
  display: block;
  padding: 7px 16px 7px 18px;
  color: #d5e4ee;
  font-size: 13.5px;
  border-left: 3px solid transparent;
}
.menu-group a:hover {
  background: rgba(255, 255, 255, .08);
  color: #fff;
  text-decoration: none;
}
.menu-group a.active {
  background: rgba(14, 138, 154, .35);
  color: #fff;
  border-left-color: #7fe0ea;
  font-weight: 700;
}

.main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--topbar-h);
  padding: 8px 16px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .spacer { flex: 1 1 auto; }
.topbar form { display: inline-flex; gap: 8px; align-items: center; margin: 0; }
.topbar .company-switch .form-control {
  width: auto;
  min-width: 220px;
  background: var(--c-input);
  border-color: var(--c-border);
}
.topbar .user-chip {
  color: var(--c-heading);
  font-size: 13px;
}

.content {
  padding: 16px;
  flex: 1 1 auto;
  width: 100%;
  max-width: none;
}

/* ---------------------------------------------------------- 頁首／卡片 */
.page-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 8px 15px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  margin-bottom: 15px;
}
.page-header h1 {
  font-size: 1.35rem;
  margin: 0;
  color: var(--c-heading);
  font-weight: 700;
}
.page-header .spacer { flex: 1 1 auto; }
.page-subtitle { color: var(--c-muted); font-size: 13px; margin: 0 0 12px; }

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}
.card > .card-header {
  padding: 8px 15px;
  min-height: 44px;
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  color: var(--c-heading);
  background: #fafbfc;
}
.card > .card-header .spacer { flex: 1 1 auto; }
.card > .card-body { padding: 15px; }
.card > .card-body.tight { padding: 0; }

/* ---------------------------------------------------------- 表格 */
table.data {
  width: 100%;
  border-collapse: collapse;
  background: var(--c-surface);
}
table.data th, table.data td {
  border-bottom: 1px solid var(--c-border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: middle;
}
table.data thead th {
  background: #f7f8fa;
  color: var(--c-heading);
  font-weight: 700;
  white-space: nowrap;
  font-size: 13px;
}
table.data tbody tr:hover { background: #f7fafb; }
table.data td.num, table.data th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
table.data td.center, table.data th.center { text-align: center; }
table.data.tight th, table.data.tight td { padding: 6px 10px; font-size: 13px; }
table.data tfoot td { font-weight: 700; background: #f7f8fa; }

.empty {
  padding: 36px 16px;
  text-align: center;
  color: var(--c-muted);
}

/* ---------------------------------------------------------- 表單 */
.form-row { display: flex; flex-wrap: wrap; gap: 14px; }
.form-field { flex: 1 1 220px; min-width: 200px; margin-bottom: 4px; }
.form-field.wide { flex: 1 1 100%; }
.form-field label { display: block; font-size: 13px; color: var(--c-muted); margin-bottom: 4px; }
.form-field .helptext { display: block; font-size: 12px; color: var(--c-muted); margin-top: 3px; }
.form-field .errorlist { color: var(--c-danger); font-size: 12px; margin: 3px 0 0; padding-left: 16px; }

.form-control,
input[type="text"], input[type="password"], input[type="email"],
input[type="number"], input[type="date"], input[type="search"],
select, textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-input);
  font-size: 14px;
  font-family: inherit;
  color: var(--c-text);
}
.form-control:focus,
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(14, 138, 154, .22);
  border-color: var(--c-cyan);
  background: #fff;
}
textarea.form-control, textarea { min-height: 72px; }

.form-actions {
  display: flex;
  gap: 10px;
  padding-top: 12px;
  margin-top: 8px;
  border-top: 1px solid var(--c-border);
}

/* ---------------------------------------------------------- 按鈕 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 6px 14px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--c-text);
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
}
.btn:hover { background: #f4f6f7; text-decoration: none; }
.btn-primary {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--c-primary-dark); color: #fff; }
.btn-danger { background: var(--c-danger); border-color: var(--c-danger); color: #fff; }
.btn-danger:hover { background: #c0392b; color: #fff; }
.btn-sm { min-height: 28px; padding: 3px 10px; font-size: 12.5px; }
.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------------------------------------------------------- 標籤 */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius);
  font-size: 12px;
  border: 1px solid var(--c-border);
  background: #f0f2f4;
  white-space: nowrap;
}
.badge-draft { background: #eceff3; color: #555; }
.badge-pending { background: #fdf3e0; color: var(--c-warning); border-color: #e8d3a8; }
.badge-approved { background: #e7f4fb; color: var(--c-primary); border-color: #bcd4ef; }
.badge-posted { background: #e5f8ee; color: #1e8449; border-color: #b3ddc6; }
.badge-cancelled { background: #f0f0f0; color: #7a7a7a; }
.badge-reversed { background: #fdecea; color: var(--c-danger); border-color: #f5c6c2; }

/* ---------------------------------------------------------- 訊息 */
.messages { margin-bottom: 12px; }
.message {
  padding: 8px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  margin-bottom: 6px;
  background: #fff;
}
.message.success { background: #e5f8ee; border-color: #b3ddc6; color: #14532d; }
.message.error { background: #fdecea; border-color: #f5c6c2; color: #7f1d1d; }
.message.warning { background: #fdf3e0; border-color: #e8d3a8; color: #713f12; }
.message.info { background: #e7f4fb; border-color: #bcd4ef; color: #1e3a5f; }

/* ---------------------------------------------------------- 篩選列 */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 15px;
  border-bottom: 1px solid var(--c-border);
  background: #fafbfc;
}
.toolbar .field { display: flex; flex-direction: column; gap: 3px; }
.toolbar label { font-size: 12px; color: var(--c-muted); }
.toolbar .form-control { min-width: 140px; }
.toolbar .spacer { flex: 1 1 auto; }

/* ---------------------------------------------------------- 分頁 */
.pagination {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 10px 15px;
  color: var(--c-muted);
  font-size: 13px;
  border-top: 1px solid var(--c-border);
}
.pagination .spacer { flex: 1 1 auto; }

/* ---------------------------------------------------------- 登入 */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--c-bg);
}
.login-card {
  width: 380px;
  background: #fff;
  border-radius: var(--radius);
  padding: 28px 28px 24px;
  border: 1px solid var(--c-border);
}
.login-card .brand-mark {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: var(--c-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  margin-bottom: 14px;
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; color: var(--c-heading); }
.login-card .sub { color: var(--c-muted); font-size: 13px; margin-bottom: 18px; }

/* ---------------------------------------------------------- 明細編輯 */
table.lines { width: 100%; border-collapse: collapse; }
table.lines th, table.lines td {
  border: 1px solid var(--c-border);
  padding: 4px 6px;
}
table.lines thead th {
  background: #f7f8fa;
  font-size: 13px;
  white-space: nowrap;
  color: var(--c-heading);
}
table.lines input, table.lines select {
  width: 100%;
  border: 1px solid transparent;
  padding: 4px 6px;
  border-radius: 3px;
  font-size: 13px;
  font-family: inherit;
  background: transparent;
}
table.lines input:focus, table.lines select:focus {
  border-color: var(--c-cyan);
  background: #fff;
  outline: none;
}
table.lines input.num { text-align: right; font-variant-numeric: tabular-nums; }
table.lines td.shrink { width: 42px; text-align: center; }

.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--c-muted); }
.kv dd { margin: 0; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px 15px;
}
.stat .label { color: var(--c-muted); font-size: 13px; }
.stat .value {
  font-size: 26px;
  font-weight: 700;
  color: var(--c-primary);
  font-variant-numeric: tabular-nums;
}

.text-muted { color: var(--c-muted); }
.text-danger { color: var(--c-danger); }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }

@media (max-width: 840px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-basis: auto;
    height: auto;
    position: relative;
  }
  .sidebar-nav { max-height: 240px; }
}
