/* ═══════════════════════════════════════════════════
   YZ ERP — 宥忠科技  主樣式表
   ═══════════════════════════════════════════════════ */

:root {
  --primary:       #2563eb;
  --primary-dark:  #1d4ed8;
  --primary-light: #eff6ff;
  --sidebar-bg:    #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-text:  #94a3b8;
  --sidebar-active:#2563eb;
  --header-h:      60px;
  --sidebar-w:     260px;
  --bg:            #f1f5f9;
  --card:          #ffffff;
  --text:          #0f172a;
  --text-2:        #64748b;
  --border:        #e2e8f0;
  --success:       #16a34a;
  --warning:       #d97706;
  --danger:        #dc2626;
  --info:          #0284c7;
  --radius:        8px;
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:     0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body { font-family: 'Segoe UI', 'Microsoft JhengHei', Arial, sans-serif;
       background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; }
input, select, textarea, button { font: inherit; }
button { cursor: pointer; border: none; background: none; }
table { border-collapse: collapse; width: 100%; }

/* ═══════════════════════════════════════════════════
   登入頁
   ═══════════════════════════════════════════════════ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #2563eb 100%);
}
.login-box {
  background: var(--card);
  border-radius: 16px;
  padding: 48px 40px;
  width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo h1 { font-size: 1.6rem; font-weight: 700; color: var(--primary); }
.login-logo p  { color: var(--text-2); font-size: .85rem; margin-top: 4px; }
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-weight: 500; margin-bottom: 6px; font-size: .85rem; }
.form-group input {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .2s;
  font-size: .9rem;
}
.form-group input:focus { outline: none; border-color: var(--primary); }
.btn-login {
  width: 100%; padding: 12px;
  background: var(--primary); color: #fff;
  border-radius: var(--radius); font-weight: 600;
  font-size: .95rem; margin-top: 8px;
  transition: background .2s;
}
.btn-login:hover { background: var(--primary-dark); }
.login-footer { text-align: center; margin-top: 24px; color: var(--text-2); font-size: .8rem; }

/* ═══════════════════════════════════════════════════
   主版面（登入後）
   ═══════════════════════════════════════════════════ */
.app-layout { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  position: fixed; top: 0; left: 0;
  height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
  z-index: 100;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }

.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid #1e293b;
}
.sidebar-brand .brand-name {
  font-size: 1.1rem; font-weight: 700; color: #fff;
  letter-spacing: .5px;
}
.sidebar-brand .brand-sub {
  font-size: .72rem; color: var(--sidebar-text); margin-top: 2px;
}

.sidebar-nav { padding: 12px 0; flex: 1; }

.nav-section-title {
  font-size: .68rem; font-weight: 600; letter-spacing: 1px;
  color: #475569; text-transform: uppercase;
  padding: 16px 20px 6px;
}

.nav-item { position: relative; }

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  color: var(--sidebar-text);
  font-size: .85rem;
  transition: background .15s, color .15s;
  border-radius: 0;
}
.nav-link:hover  { background: var(--sidebar-hover); color: #e2e8f0; }
.nav-link.active { background: var(--sidebar-active); color: #fff; }
.nav-link .icon  { width: 18px; text-align: center; opacity: .8; font-size: .9rem; }
.nav-link .arrow {
  margin-left: auto; font-size: .7rem;
  transition: transform .2s;
}
.nav-item.open .arrow { transform: rotate(90deg); }

.nav-sub {
  background: rgba(0,0,0,.2);
  display: none;
}
.nav-item.open .nav-sub { display: block; }
.nav-sub .nav-link {
  padding: 7px 20px 7px 48px;
  font-size: .82rem;
}

/* ── Header ── */
.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
}
.header {
  height: var(--header-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.header-breadcrumb {
  font-size: .85rem; color: var(--text-2);
  display: flex; align-items: center; gap: 6px;
}
.header-breadcrumb .current { color: var(--text); font-weight: 500; }
.header-right {
  margin-left: auto; display: flex; align-items: center; gap: 16px;
}
.header-right .user-info {
  display: flex; align-items: center; gap: 8px;
  font-size: .85rem; color: var(--text-2);
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .8rem;
}
.btn-icon {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2); font-size: 1.1rem;
  transition: background .15s;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }

/* ── Content ── */
.content {
  padding: 24px;
  flex: 1;
}
.page-title {
  font-size: 1.3rem; font-weight: 700; margin-bottom: 20px;
  color: var(--text);
}

/* ── Footer ── */
.footer {
  text-align: center;
  padding: 14px 24px;
  font-size: .75rem;
  color: var(--text-2);
  border-top: 1px solid var(--border);
  background: var(--card);
}

/* ═══════════════════════════════════════════════════
   共用元件
   ═══════════════════════════════════════════════════ */

/* Card */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-header h3 { font-size: .95rem; font-weight: 600; }
.card-body { padding: 20px; }

/* KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
}
.kpi-icon {
  width: 52px; height: 52px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
}
.kpi-icon.blue   { background: #eff6ff; color: var(--primary); }
.kpi-icon.green  { background: #f0fdf4; color: var(--success); }
.kpi-icon.orange { background: #fffbeb; color: var(--warning); }
.kpi-icon.red    { background: #fef2f2; color: var(--danger); }
.kpi-icon.purple { background: #f5f3ff; color: #7c3aed; }
.kpi-info .label { font-size: .78rem; color: var(--text-2); margin-bottom: 4px; }
.kpi-info .value { font-size: 1.4rem; font-weight: 700; }
.kpi-info .trend { font-size: .75rem; margin-top: 2px; }
.trend.up   { color: var(--success); }
.trend.down { color: var(--danger); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  font-weight: 500; font-size: .85rem;
  transition: background .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-success   { background: var(--success); color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: .78rem; }
.btn-outline {
  background: transparent; color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }

/* Table */
.table-wrap { overflow-x: auto; }
.data-table th, .data-table td {
  padding: 11px 14px;
  text-align: left;
  font-size: .85rem;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--text-2);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .5px;
  white-space: nowrap;
}
.data-table tr:hover td { background: #f8fafc; }
.data-table td:last-child { white-space: nowrap; }

/* Badge */
.badge {
  display: inline-block;
  padding: 2px 10px; border-radius: 100px;
  font-size: .72rem; font-weight: 600;
}
.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef9c3; color: #a16207; }
.badge-danger  { background: #fee2e2; color: #b91c1c; }
.badge-info    { background: #dbeafe; color: #1d4ed8; }
.badge-gray    { background: #f1f5f9; color: #475569; }

/* Toolbar */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.search-box {
  position: relative; flex: 1; min-width: 200px;
}
.search-box input {
  width: 100%; padding: 8px 14px 8px 36px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .85rem;
  transition: border-color .2s;
}
.search-box input:focus { outline: none; border-color: var(--primary); }
.search-box .search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-2); font-size: .9rem;
}
.select-filter {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .85rem;
  background: var(--card);
}
.select-filter:focus { outline: none; border-color: var(--primary); }

/* Pagination */
.pagination {
  display: flex; align-items: center; gap: 4px;
  justify-content: flex-end; margin-top: 16px;
}
.page-btn {
  width: 32px; height: 32px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: .82rem; color: var(--text-2);
  border: 1px solid var(--border);
  transition: background .15s;
}
.page-btn:hover   { background: var(--bg); }
.page-btn.active  { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Form */
.form-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: .82rem; font-weight: 500; color: var(--text-2); }
.field input, .field select, .field textarea {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .85rem;
  transition: border-color .2s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary);
}
.field textarea { resize: vertical; min-height: 80px; }

/* Modal */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 200;
  align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--card); border-radius: 12px;
  width: 92%; max-width: 680px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-md);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1 1 auto;
}
.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
  flex-shrink: 0;
}

/* Summary table (財務報表用) */
.report-table th, .report-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: .87rem;
}
.report-table th { font-weight: 600; background: #f8fafc; }
.report-table .subtotal td { font-weight: 600; background: #f8fafc; }
.report-table .total td    { font-weight: 700; background: #eff6ff; color: var(--primary); font-size: .95rem; }
.report-table .indent { padding-left: 36px !important; }
.report-table .section-title td {
  font-weight: 700; font-size: .82rem;
  text-transform: uppercase; letter-spacing: .5px;
  background: #f1f5f9; color: var(--text-2);
}

/* Charts placeholder */
.chart-placeholder {
  background: #f8fafc;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2); font-size: .85rem;
  border: 2px dashed var(--border);
}

/* Two-column layout */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* Account code styling */
.acct-code { font-family: monospace; font-size: .82rem; color: var(--text-2); }

/* Amount cells */
.amount { text-align: right; font-variant-numeric: tabular-nums; }
.amount-dr { color: var(--danger); }
.amount-cr { color: var(--success); }

/* Notification dot */
.notif-dot {
  display: inline-block; width: 8px; height: 8px;
  background: var(--danger); border-radius: 50%;
  margin-left: 4px;
}

/* Tab nav */
.tab-nav {
  display: flex; border-bottom: 2px solid var(--border);
  margin-bottom: 20px; gap: 0;
}
.tab-btn {
  padding: 10px 20px; font-size: .87rem; font-weight: 500;
  color: var(--text-2); border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: color .15s, border-color .15s;
}
.tab-btn:hover  { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* Utility */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-2); }
.text-danger { color: var(--danger); }
.text-success{ color: var(--success); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.fw-bold { font-weight: 700; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 16px; }
.flex-1 { flex: 1; }
.w-100 { width: 100%; }

/* Page title bar with action button */
.page-title-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.page-title-bar .page-title { margin-bottom: 0; }

/* Card footer */
.card-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}
.card-footer .pagination { margin-top: 0; }

/* Financial statement table styles */
.fin-table th, .fin-table td {
  padding: 9px 16px;
  font-size: .87rem;
  border-bottom: 1px solid var(--border);
}
.fin-table tfoot td {
  border-top: 2px solid var(--border);
  border-bottom: none;
  background: #f0f9ff;
  font-weight: 700;
}
.fin-section td {
  font-weight: 700; font-size: .82rem;
  background: #f8fafc; color: var(--text-2);
  padding: 8px 16px !important;
  border-bottom: 1px solid var(--border);
}
.fin-subtotal td {
  font-weight: 700;
  background: #f8fafc;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

/* Report item in reports.html */
.report-item {
  display: flex; align-items: center; gap: 14px;
  padding: 12px; background: #f8fafc;
  border-radius: 8px; border: 1px solid var(--border);
  cursor: pointer; transition: background .15s;
}
.report-item:hover { background: var(--primary-light); }
.report-title { font-weight: 600; font-size: .88rem; }
.report-desc  { font-size: .78rem; color: var(--text-2); margin-top: 2px; }
.report-item button { margin-left: auto; flex-shrink: 0; }
