/* ========== 社區管理系統 CSS ========== */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --info: #0ea5e9;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-500: #64748b;
  --gray-700: #334155;
  --gray-900: #0f172a;
  --sidebar-width: 240px;
  --topbar-height: 60px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, "Microsoft JhengHei", sans-serif; background: var(--gray-100); color: var(--gray-900); font-size: 14px; }

/* Login */
.login-screen { display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: 20px;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 60%, #3b82f6 100%); position: relative; overflow: hidden; }
.login-screen::before { content: ""; position: absolute; width: 480px; height: 480px; border-radius: 50%;
  background: rgba(255,255,255,0.06); top: -160px; right: -120px; }
.login-screen::after { content: ""; position: absolute; width: 360px; height: 360px; border-radius: 50%;
  background: rgba(255,255,255,0.05); bottom: -140px; left: -100px; }
.login-box { position: relative; z-index: 1; background: white; padding: 44px 40px 32px; border-radius: 20px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.35); text-align: center; width: 400px; max-width: 92vw; animation: loginUp .4s ease; }
@keyframes loginUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.login-logo { width: 76px; height: 76px; margin: 0 auto 16px; border-radius: 20px; font-size: 38px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); box-shadow: 0 8px 20px rgba(37,99,235,.35); }
.login-box h1 { font-size: 26px; color: var(--gray-900); margin-bottom: 6px; letter-spacing: 1px; }
.login-box .subtitle { color: var(--gray-500); margin-bottom: 28px; font-size: 14px; }
.login-form .input-group { position: relative; margin-bottom: 14px; }
.login-form .input-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-size: 16px; opacity: .7; }
.login-form input { width: 100%; padding: 13px 16px 13px 42px; border: 2px solid var(--gray-200); border-radius: 10px;
  font-size: 15px; outline: none; transition: all 0.2s; background: var(--gray-50); }
.login-form input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px var(--primary-light); }
.login-form button { width: 100%; padding: 14px; margin-top: 6px; background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white; border: none; border-radius: 10px; font-size: 16px; letter-spacing: 4px; cursor: pointer;
  transition: all 0.2s; box-shadow: 0 6px 16px rgba(37,99,235,.3); }
.login-form button:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(37,99,235,.42); }
.login-foot { margin-top: 22px; color: var(--gray-300); font-size: 12px; }

/* Layout */
#sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-width); background: var(--gray-900); color: white; z-index: 100; display: flex; flex-direction: column; }
.sidebar-header { padding: 24px 20px; border-bottom: 1px solid var(--gray-700); }
.sidebar-header h2 { font-size: 18px; margin-bottom: 4px; }
#sidebar-badge { font-size: 11px; background: var(--primary); padding: 2px 8px; border-radius: 10px; }
#nav-menu { list-style: none; flex: 1; padding: 12px 0; }
#nav-menu li { padding: 12px 20px; cursor: pointer; display: flex; align-items: center; gap: 10px; transition: background 0.15s; color: var(--gray-300); }
#nav-menu li:hover { background: rgba(255,255,255,0.08); color: white; }
#nav-menu li.active { background: var(--primary); color: white; border-right: 3px solid var(--primary-light); }
#nav-menu li .icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--gray-700); }
.sidebar-footer button { width: 100%; padding: 10px; background: transparent; color: var(--gray-300); border: 1px solid var(--gray-700); border-radius: 6px; cursor: pointer; }
.sidebar-footer button:hover { background: rgba(255,255,255,0.08); color: white; }

#content { margin-left: var(--sidebar-width); min-height: 100vh; }
#top-bar { height: var(--topbar-height); background: white; border-bottom: 1px solid var(--gray-200); display: flex; justify-content: space-between; align-items: center; padding: 0 24px; }
#top-bar h2 { font-size: 20px; color: var(--gray-900); }
#user-info { color: var(--gray-500); font-size: 13px; }
#page-container { padding: 24px; }

/* Cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: white; border-radius: 12px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); display: flex; flex-direction: column; gap: 8px; }
.stat-card .stat-label { color: var(--gray-500); font-size: 13px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; }
.stat-card.primary .stat-value { color: var(--primary); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.danger .stat-value { color: var(--danger); }

/* Tables */
.card { background: white; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); margin-bottom: 20px; overflow: hidden; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--gray-200); display: flex; justify-content: space-between; align-items: center; }
.card-header h3 { font-size: 16px; }
table { width: 100%; border-collapse: collapse; }
th { background: var(--gray-50); padding: 10px 16px; text-align: left; font-weight: 600; color: var(--gray-700); border-bottom: 2px solid var(--gray-200); font-size: 13px; }
td { padding: 10px 16px; border-bottom: 1px solid var(--gray-100); }
tr:hover td { background: var(--gray-50); }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-default { background: var(--gray-100); color: var(--gray-700); }

/* Buttons */
.btn { padding: 8px 16px; border: none; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 500; transition: all 0.15s; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-outline { background: white; border: 1px solid var(--gray-300); color: var(--gray-700); }
.btn-outline:hover { background: var(--gray-50); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; color: var(--gray-700); font-size: 13px; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--gray-300); border-radius: 6px; font-size: 14px; outline: none; transition: border 0.2s; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }

/* Modal */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 1000; justify-content: center; align-items: center; }
.modal-overlay.show { display: flex; }
.modal { background: white; border-radius: 12px; width: 600px; max-width: 90vw; max-height: 80vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--gray-200); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 18px; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--gray-500); }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: 8px; }

/* Search */
.search-bar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.search-bar input, .search-bar select { padding: 8px 12px; border: 1px solid var(--gray-300); border-radius: 6px; font-size: 13px; }
.search-bar input { flex: 1; min-width: 200px; }

/* Pagination */
.pagination { display: flex; justify-content: center; gap: 4px; margin-top: 16px; }
.pagination button { padding: 6px 12px; border: 1px solid var(--gray-300); background: white; border-radius: 4px; cursor: pointer; }
.pagination button.active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination button:hover:not(.active) { background: var(--gray-50); }

/* Loading */
.loading { text-align: center; padding: 40px; color: var(--gray-500); }
.loading::after { content: "..."; animation: dots 1.5s infinite; }
@keyframes dots { 0% { content: "."; } 33% { content: ".."; } 66% { content: "..."; } }

/* Responsive */
@media (max-width: 768px) {
  #sidebar { width: 56px; }
  .sidebar-header { padding: 16px 0; text-align: center; }
  .sidebar-header h2, #sidebar-badge, .sidebar-footer span, #nav-menu li span:not(.icon) { display: none; }
  #nav-menu li { justify-content: center; padding: 14px 0; }
  #nav-menu li .icon { width: auto; font-size: 18px; }
  .sidebar-footer { padding: 12px 6px; }
  #content { margin-left: 56px; }
  #top-bar { padding: 0 14px; }
  #top-bar h2 { font-size: 17px; }
  #user-info { font-size: 12px; }
  #page-container { padding: 14px; }

  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card .stat-value { font-size: 22px; }

  /* 表格自身水平捲動、欄位不換行（同時適用卡片內與裸表格，避免破版）*/
  #content table, .modal-body table {
    display: block; width: 100%; overflow-x: auto; white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  /* 對話框近全寬，內部寬表格可橫向捲動 */
  .modal { width: 96vw; max-width: 96vw; max-height: 88vh; }
  .modal-body { padding: 14px; overflow-x: auto; }
  .modal-footer { flex-wrap: wrap; }

  /* 內嵌雙欄網格改單欄（以 !important 覆蓋行內樣式）*/
  .dash-2 { grid-template-columns: 1fr !important; }
  .modal-stat-grid { grid-template-columns: 1fr 1fr !important; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .btn { padding: 8px 12px; }
  .modal-stat-grid { grid-template-columns: 1fr !important; }
}

/* Vendor detail tabs */
.tabs { display:flex; gap:4px; margin-bottom:16px; flex-wrap:wrap; }
.tab-btn { padding:8px 16px; border:1px solid #ddd; background:#f8f9fa; cursor:pointer; border-radius:6px; font-size:13px; }
.tab-btn.active { background:#007bff; color:#fff; border-color:#007bff; }
.tab-content { display:none; }
.tab-content.active { display:block; }
.tab-content table { margin-top:12px; }

/* Vendor detail buttons */
.btn-sm { padding:4px 8px; font-size:12px; }
.btn-success { background:#28a745; color:#fff; border:none; cursor:pointer; border-radius:4px; }
.btn-danger { background:#dc3545; color:#fff; border:none; cursor:pointer; border-radius:4px; }
