/* ════════════════════════════════════════════
   陸旺畜產 進銷存管理系統 — ERP Style CSS
   ════════════════════════════════════════════ */

/* ── CSS 變數 ──────────────────────────────── */
:root {
  --sidebar-bg:   #1a2235;
  --sidebar-hover:#243047;
  --sidebar-active:#2d6a4f;
  --brand-color:  #2d6a4f;
  --brand-light:  #52b788;
  --accent:       #e76f51;
  --danger:       #e63946;
  --warning:      #f4a261;
  --success:      #2d6a4f;
  --info:         #457b9d;

  --bg:           #f0f2f5;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --text:         #1e293b;
  --text-muted:   #64748b;
  --text-light:   #94a3b8;

  --sidebar-w:    220px;
  --topbar-h:     56px;
  --radius:       8px;
  --shadow:       0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
}

/* ── Reset ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Segoe UI', 'PingFang TC', 'Microsoft JhengHei', sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }
.hidden { display: none !important; }

/* ── 登入畫面 ──────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a2235 0%, #2d6a4f 100%);
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  text-align: center;
}
.login-logo {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, var(--brand-color), var(--brand-light));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
  font-size: 28px; color: #fff;
}
.login-title { font-size: 24px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.login-sub   { color: var(--text-muted); margin-bottom: 32px; font-size: 13px; }
.login-form  { text-align: left; }
.login-err   { color: var(--danger); font-size: 13px; margin-top: 12px; text-align: center; min-height: 20px; }

/* ── 主應用佈局 ─────────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── 側欄 ──────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform .25s ease;
  z-index: 200;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px;
  font-size: 16px; font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand i { font-size: 20px; color: var(--brand-light); }

.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-section-label {
  font-size: 10px; font-weight: 600; letter-spacing: .08em;
  color: rgba(255,255,255,.35);
  padding: 16px 20px 6px;
  text-transform: uppercase;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px;
  color: rgba(255,255,255,.7);
  border-left: 3px solid transparent;
  transition: all .15s;
  cursor: pointer;
  font-size: 13.5px;
}
.nav-item i { width: 18px; text-align: center; font-size: 14px; flex-shrink: 0; }
.nav-item:hover  { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-hover); color: #fff; border-left-color: var(--brand-light); }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.btn-logout {
  background: none; border: 1px solid rgba(255,255,255,.2);
  color: rgba(255,255,255,.6);
  padding: 8px 16px; border-radius: 6px;
  font-size: 13px; width: 100%;
  transition: all .15s;
}
.btn-logout:hover { background: rgba(255,255,255,.08); color: #fff; }

/* ── 主內容區 ──────────────────────────────── */
.main-wrapper {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0; overflow: hidden;
}

/* ── Topbar ────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px;
  gap: 16px;
  box-shadow: var(--shadow);
  flex-shrink: 0;
  z-index: 100;
}
.sidebar-toggle {
  background: none; border: none;
  color: var(--text-muted); font-size: 18px;
  padding: 4px; display: none;
}
.page-title { font-size: 16px; font-weight: 600; color: var(--text); flex: 1; }
.topbar-date { color: var(--text-muted); font-size: 13px; }

/* ── 頁面內容 ──────────────────────────────── */
.page-content {
  flex: 1; overflow-y: auto;
  padding: 24px;
}

/* ── 通用元件 ──────────────────────────────── */

/* 卡片 */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.card-title { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

/* 數據卡 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px;
}
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text); }
.stat-sub   { font-size: 12px; color: var(--text-muted); }
.stat-card.green  { border-left: 4px solid var(--brand-color); }
.stat-card.red    { border-left: 4px solid var(--danger); }
.stat-card.orange { border-left: 4px solid var(--warning); }
.stat-card.blue   { border-left: 4px solid var(--info); }

/* 按鈕 */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 6px;
  font-size: 13.5px; font-weight: 500;
  border: none; transition: all .15s;
  cursor: pointer;
}
.btn-primary   { background: var(--brand-color); color: #fff; }
.btn-primary:hover { background: #245a40; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #d1d5db; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c1121f; }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #e07b2e; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-outline:hover { border-color: var(--brand-color); color: var(--brand-color); }

/* 表格 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: #f8fafc;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* 表單 */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 13px;
  font-weight: 500; color: var(--text-muted);
  margin-bottom: 6px;
}
.form-control {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px; color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--brand-color);
  box-shadow: 0 0 0 3px rgba(45,106,79,.1);
}
.form-control:read-only { background: #f8fafc; color: var(--text-muted); }
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.form-hint { font-size: 12px; color: var(--text-light); margin-top: 4px; }

/* 狀態 Badge */
.badge {
  display: inline-block; padding: 3px 8px;
  border-radius: 99px; font-size: 11px; font-weight: 600;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-gray    { background: #f1f5f9; color: #475569; }

/* 工具列 */
.toolbar {
  display: flex; align-items: center;
  gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar-left  { flex: 1; display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar-right { display: flex; gap: 8px; }

/* 搜尋輸入 */
.search-input {
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--border);
  border-radius: 6px; font-size: 13px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E") no-repeat 10px center;
  width: 200px;
}
.search-input:focus { outline: none; border-color: var(--brand-color); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-lg { max-width: 720px; }
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none; border: none;
  color: var(--text-muted); font-size: 20px;
  padding: 2px 6px; border-radius: 4px;
  transition: color .15s;
}
.modal-close:hover { color: var(--text); }
.modal-body   { padding: 20px 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* 公式計算高亮 */
.calc-box {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  padding: 12px 16px;
  margin: 12px 0;
  font-size: 13px; color: #166534;
}
.calc-box strong { font-size: 15px; }

/* 篩選列 */
.filter-bar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 16px;
}

/* 報表 */
.report-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px;
}
.report-period { font-size: 13px; color: var(--text-muted); }
.chart-wrap {
  height: 260px; position: relative;
  margin-top: 12px;
}

/* 月份選擇 */
.period-selector {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
}
.period-selector input,
.period-selector select {
  border: none; background: transparent;
  font-size: 14px; color: var(--text);
  padding: 0;
}
.period-selector input:focus,
.period-selector select:focus { outline: none; }

/* 空資料 */
.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state i { font-size: 40px; margin-bottom: 12px; opacity: .4; display: block; }
.empty-state p { font-size: 14px; }

/* 金額顯示 */
.amount-positive { color: var(--brand-color); font-weight: 600; }
.amount-negative { color: var(--danger); font-weight: 600; }
.amount-neutral  { color: var(--text); }

/* 付款狀態顏色 */
.status-paid     { color: #065f46; }
.status-partial  { color: #92400e; }
.status-unpaid   { color: #991b1b; }

/* 小標籤列 */
.tag-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tag {
  font-size: 11px; padding: 2px 8px; border-radius: 99px;
  background: #f1f5f9; color: var(--text-muted);
}

/* 麵包屑 */
.breadcrumb {
  font-size: 12px; color: var(--text-muted); margin-bottom: 16px;
}

/* 頁面標題列 */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.section-title { font-size: 18px; font-weight: 700; }

/* 分隔線 */
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* 計算公式顯示列 */
.formula-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-muted);
  padding: 8px 0;
}
.formula-val { font-weight: 600; color: var(--text); font-size: 15px; }

/* 表格操作欄 */
.action-btns { display: flex; gap: 6px; white-space: nowrap; }

/* Toast 通知 */
.toast-wrap {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 9999; display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: #1e293b; color: #fff;
  padding: 12px 20px; border-radius: 8px;
  font-size: 13px; box-shadow: var(--shadow-md);
  animation: toastIn .25s ease;
  pointer-events: auto;
}
.toast.success { background: var(--brand-color); }
.toast.error   { background: var(--danger); }
.toast.warning { background: var(--warning); color: #fff; }
@keyframes toastIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── 響應式 ────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: block; }
  .page-content { padding: 16px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row  { grid-template-columns: 1fr; }
  .modal     { max-width: 100%; border-radius: 12px 12px 0 0; align-self: flex-end; }
  .modal-overlay { align-items: flex-end; padding: 0; }
}
