/* ========================================================
   得人疼餐飲管理系統 — Premium Design System
   ======================================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Noto+Sans+TC:wght@400;500;600;700&display=swap');

:root {
  --green-50: #f0fdf4; --green-100: #dcfce7; --green-500: #22c55e; --green-600: #16a34a; --green-700: #15803d;
  --blue-50: #eff6ff; --blue-100: #dbeafe; --blue-500: #3b82f6;
  --orange-50: #fff7ed; --orange-100: #ffedd5; --orange-500: #f97316;
  --yellow-50: #fefce8; --yellow-100: #fef9c3; --yellow-500: #eab308;
  --purple-50: #faf5ff; --purple-100: #f3e8ff; --purple-500: #a855f7;
  --pink-50: #fdf2f8; --pink-100: #fce7f3;
  --gray-50: #f9fafb; --gray-100: #f3f4f6; --gray-200: #e5e7eb; --gray-300: #d1d5db;
  --gray-400: #9ca3af; --gray-500: #6b7280; --gray-600: #4b5563; --gray-700: #374151;
  --gray-800: #1f2937; --gray-900: #111827;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
  --shadow-card: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.02);
  --radius-sm: 8px; --radius-md: 12px; --radius-lg: 16px; --radius-xl: 20px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: 'Inter', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif; color: var(--gray-800); background: #f5f7fa; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #e8faf0 0%, #eef4ff 50%, #fef9ee 100%);
}
.login-card {
  background: white; padding: 44px 40px; border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg); width: 400px; max-width: 92vw;
}
.login-card h1 { margin: 0 0 6px; font-size: 21px; font-weight: 700; display: flex; align-items: center; gap: 10px; letter-spacing: -0.02em; }
.login-card .subtitle { color: var(--gray-500); font-size: 14px; margin-bottom: 28px; }
.login-card label { display: block; font-size: 13px; font-weight: 500; color: var(--gray-600); margin: 16px 0 6px; }
.login-card input { width: 100%; padding: 11px 14px; border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm); font-size: 14px; transition: border-color 0.15s; }
.login-card input:focus { outline: none; border-color: var(--green-500); box-shadow: 0 0 0 3px rgba(34,197,94,0.1); }
.login-card button { width: 100%; margin-top: 24px; padding: 12px; background: linear-gradient(135deg, var(--green-600), var(--green-500)); color: white; border: 0; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; letter-spacing: 0.02em; transition: transform 0.1s, box-shadow 0.15s; }
.login-card button:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(22,163,74,0.3); }
.login-card button:active { transform: translateY(0); }
.login-hint { margin-top: 18px; font-size: 11px; color: var(--gray-400); text-align: center; line-height: 1.7; }
.error { color: #dc2626; font-size: 13px; margin-top: 12px; }

/* ---------- App layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: white; border-right: 1px solid rgba(0,0,0,0.06);
  display: flex; flex-direction: column; flex-shrink: 0;
  box-shadow: 1px 0 8px rgba(0,0,0,0.03);
}
.brand { padding: 20px 22px; display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.brand-icon { width: 32px; height: 32px; background: linear-gradient(135deg, var(--green-500), #34d399); color: white; border-radius: 10px; display: grid; place-items: center; font-size: 16px; box-shadow: 0 2px 8px rgba(34,197,94,0.25); }
.store-select { margin: 0 16px 16px; }
.store-select select { width: 100%; padding: 9px 12px; border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm); background: var(--gray-50); font-size: 13px; font-weight: 500; transition: border-color 0.15s; }
.store-select select:focus { outline: none; border-color: var(--green-500); }

.nav-group-label { padding: 18px 22px 6px; font-size: 10px; font-weight: 600; color: var(--gray-400); letter-spacing: 0.08em; text-transform: uppercase; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 22px; font-size: 13.5px; color: var(--gray-600); cursor: pointer; transition: all 0.1s; border-left: 3px solid transparent; font-weight: 450; }
.nav-item:hover { background: var(--gray-50); color: var(--gray-800); }
.nav-item.active { background: var(--green-50); color: var(--green-700); border-left-color: var(--green-500); font-weight: 600; }
.nav-icon { width: 18px; text-align: center; font-size: 14px; }

.user-card { margin-top: auto; padding: 16px 18px; border-top: 1px solid var(--gray-100); display: flex; align-items: center; gap: 10px; font-size: 13px; }
.user-avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, #fde68a, #fbbf24); color: #92400e; display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.user-card .uname { font-weight: 600; font-size: 13px; }
.user-card .uemail { color: var(--gray-400); font-size: 11px; }
.logout-btn { background: none; border: 0; color: #ef4444; font-size: 13px; padding: 4px 8px; border-radius: 6px; }
.logout-btn:hover { background: #fef2f2; }

.main { flex: 1; padding: 30px 40px; overflow-x: auto; }

/* ---------- Page header ---------- */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 28px; flex-wrap: wrap; gap: 12px; }
.page-title h1 { margin: 0 0 4px; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.page-title p { margin: 0; color: var(--gray-500); font-size: 13px; }
.month-picker { display: flex; align-items: center; gap: 6px; background: white; padding: 6px 10px; border-radius: var(--radius-md); border: 1.5px solid var(--gray-200); font-size: 13px; box-shadow: var(--shadow-sm); }
.month-picker button { background: none; border: 0; color: var(--gray-500); padding: 4px 8px; border-radius: 6px; font-size: 14px; }
.month-picker button:hover { background: var(--gray-100); color: var(--gray-800); }

/* Date picker toolbar for daily switching */
.date-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.date-toolbar input[type="date"] { padding: 7px 12px; border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; background: white; box-shadow: var(--shadow-sm); }
.date-toolbar input[type="date"]:focus { outline: none; border-color: var(--green-500); }
.date-nav { display: flex; gap: 2px; }
.date-nav button { background: white; border: 1.5px solid var(--gray-200); color: var(--gray-600); padding: 6px 10px; font-size: 13px; cursor: pointer; transition: all 0.1s; }
.date-nav button:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.date-nav button:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.date-nav button:hover { background: var(--gray-50); }
.date-nav button.active { background: var(--green-600); color: white; border-color: var(--green-600); }

.section-title { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--gray-600); margin: 22px 0 12px; letter-spacing: 0.01em; }

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.card {
  background: white; padding: 20px 22px; border-radius: var(--radius-md);
  border: 1px solid rgba(0,0,0,0.04);
  box-shadow: var(--shadow-card);
  transition: transform 0.12s, box-shadow 0.12s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.card .label { color: var(--gray-500); font-size: 12px; font-weight: 500; display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.card .icon-bg { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; font-size: 14px; flex-shrink: 0; }
.card .value { font-size: 24px; font-weight: 700; color: var(--gray-900); letter-spacing: -0.02em; }
.card .sub { color: var(--gray-400); font-size: 11px; margin-top: 6px; font-weight: 500; }

.bg-green { background: var(--green-50); color: var(--green-600); }
.bg-blue { background: var(--blue-50); color: var(--blue-500); }
.bg-orange { background: var(--orange-50); color: var(--orange-500); }
.bg-yellow { background: var(--yellow-50); color: var(--yellow-500); }
.bg-purple { background: var(--purple-50); color: var(--purple-500); }

.card-tinted-green { background: linear-gradient(135deg, #f0fdf4, #ecfdf5); border-color: rgba(34,197,94,0.1); }
.card-tinted-blue { background: linear-gradient(135deg, #eff6ff, #dbeafe40); border-color: rgba(59,130,246,0.1); }
.card-tinted-orange { background: linear-gradient(135deg, #fff7ed, #ffedd5); border-color: rgba(249,115,22,0.1); }
.card-tinted-yellow { background: linear-gradient(135deg, #fefce8, #fef9c3); border-color: rgba(234,179,8,0.1); }
.card-tinted-purple { background: linear-gradient(135deg, #faf5ff, #f3e8ff); border-color: rgba(168,85,247,0.1); }
.card-tinted-pink { background: linear-gradient(135deg, #fdf2f8, #fce7f3); border-color: rgba(236,72,153,0.1); }
.card-tinted-mint { background: linear-gradient(135deg, #f0fdfa, #ccfbf1); }

/* ---------- Two-column ---------- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 20px; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }
.panel {
  background: white; border: 1px solid rgba(0,0,0,0.04); border-radius: var(--radius-md);
  padding: 20px 22px; box-shadow: var(--shadow-card);
}
.panel h3 { margin: 0 0 16px; font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 10px; text-align: left; border-bottom: 1px solid var(--gray-100); }
th { color: var(--gray-500); font-weight: 600; font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: var(--gray-50); }
.right { text-align: right; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; box-shadow: 0 0 0 2px rgba(0,0,0,0.06); }
.tag { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 500; background: var(--gray-100); color: var(--gray-600); }
.tag-green { background: var(--green-100); color: var(--green-700); }
.tag-red { background: #fee2e2; color: #b91c1c; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.form-grid label { font-size: 12px; font-weight: 500; color: var(--gray-500); }
.form-grid input, .form-grid select, .form-grid textarea {
  width: 100%; padding: 9px 12px; border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm);
  font-size: 13px; margin-top: 5px; transition: border-color 0.15s;
}
.form-grid input:focus, .form-grid select:focus { outline: none; border-color: var(--green-500); box-shadow: 0 0 0 3px rgba(34,197,94,0.08); }
.form-actions { margin-top: 20px; display: flex; gap: 10px; align-items: center; }
.btn { padding: 10px 18px; border-radius: var(--radius-sm); border: 0; font-weight: 600; font-size: 13px; letter-spacing: 0.01em; transition: all 0.12s; }
.btn-primary { background: linear-gradient(135deg, var(--green-600), var(--green-500)); color: white; box-shadow: 0 2px 8px rgba(22,163,74,0.2); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(22,163,74,0.3); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 6px; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar select, .toolbar input { padding: 8px 12px; border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm); font-size: 13px; background: white; }

.toast { position: fixed; bottom: 24px; right: 24px; background: var(--gray-900); color: white; padding: 12px 20px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg); opacity: 0; transition: opacity 0.2s; }
.toast.show { opacity: 1; }

.empty { text-align: center; padding: 48px; color: var(--gray-400); font-size: 13px; }

/* ---------- Chart ---------- */
.chart-wrap { position: relative; height: 240px; }

.kpi-strip { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; font-size: 12px; color: var(--gray-500); }
.kpi-strip .badge { background: white; padding: 7px 12px; border: 1px solid var(--gray-100); border-radius: var(--radius-sm); font-weight: 500; box-shadow: var(--shadow-sm); }

.tabs { display: flex; gap: 4px; border-bottom: 1.5px solid var(--gray-100); margin-bottom: 18px; }
.tab { padding: 10px 16px; font-size: 13px; color: var(--gray-500); cursor: pointer; border-bottom: 2px solid transparent; font-weight: 500; }
.tab.active { color: var(--green-600); border-bottom-color: var(--green-500); font-weight: 600; }

/* ---------- Photo Upload ---------- */
.upload-area {
  border: 2px dashed var(--gray-300); border-radius: var(--radius-md); padding: 36px 20px;
  text-align: center; cursor: pointer; transition: all 0.2s;
  background: var(--gray-50);
}
.upload-area:hover, .upload-area.drag-over { border-color: var(--green-500); background: var(--green-50); }
.upload-icon { font-size: 40px; margin-bottom: 10px; }
.upload-text { color: var(--gray-600); font-size: 14px; line-height: 1.7; font-weight: 450; }

.photo-previews { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.thumb-card {
  position: relative; width: 100px; height: 100px; border-radius: var(--radius-sm);
  overflow: hidden; border: 1.5px solid var(--gray-200); background: var(--gray-50); flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.thumb-card img { width: 100%; height: 100%; object-fit: cover; }
.thumb-name { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,0.65); color: white; font-size: 10px; padding: 3px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; backdrop-filter: blur(4px); }
.thumb-del { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0,0,0,0.5); color: white; border: 0; font-size: 14px; cursor: pointer; line-height: 22px; padding: 0; backdrop-filter: blur(4px); }

.scan-status { font-size: 13px; color: var(--gray-500); padding: 4px 0; font-weight: 500; }
.scan-result-card { transition: opacity 0.3s; }
.scan-result-header { display: flex; gap: 14px; align-items: flex-start; }
.scan-thumb { width: 80px; height: 80px; border-radius: var(--radius-sm); overflow: hidden; flex-shrink: 0; box-shadow: var(--shadow-sm); }
.scan-thumb img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Mobile ---------- */
.menu-toggle { display: none; background: none; border: 0; font-size: 22px; padding: 8px; cursor: pointer; color: var(--gray-700); }

@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar {
    position: fixed; z-index: 100; width: 270px; height: 100vh;
    transform: translateX(-100%); transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    box-shadow: 4px 0 24px rgba(0,0,0,0.12);
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { display: none; position: fixed; inset: 0; z-index: 99; background: rgba(0,0,0,0.35); backdrop-filter: blur(2px); }
  .sidebar-overlay.show { display: block; }
  .menu-toggle { display: block; }
  .main { padding: 16px; padding-top: 56px; }
  .mobile-header {
    position: fixed; top: 0; left: 0; right: 0; z-index: 50;
    background: white; border-bottom: 1px solid var(--gray-100);
    display: flex; align-items: center; padding: 10px 14px; gap: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
  }
  .mobile-header .brand { padding: 0; font-size: 14px; }
  .page-header { flex-direction: column; gap: 10px; align-items: stretch; }
  .month-picker { align-self: flex-start; }
  .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card { padding: 14px; }
  .card .value { font-size: 18px; }
  .two-col { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; gap: 12px; }
  /* Larger touch targets */
  .form-grid input, .form-grid select, .form-grid textarea {
    padding: 12px 14px; font-size: 16px; /* 16px prevents iOS zoom */
  }
  .btn { min-height: 44px; padding: 10px 18px; font-size: 14px; }
  .btn-sm { min-height: 36px; padding: 8px 12px; font-size: 12px; }
  .nav-item { padding: 14px 22px; font-size: 14px; }
  .chart-wrap { height: 200px; }
  /* Horizontal scroll for wide tables instead of overflow */
  .panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { font-size: 12px; min-width: max-content; }
  th, td { padding: 8px 6px; white-space: nowrap; }
  .upload-area { padding: 24px 14px; }
  .thumb-card { width: 80px; height: 80px; }
  .scan-thumb { width: 60px; height: 60px; }
  .user-card { padding: 14px; }
  .date-toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .kpi-strip { flex-wrap: wrap; gap: 6px; }
  .form-actions { flex-wrap: wrap; gap: 8px; }
  .form-actions button { flex: 1 1 auto; min-width: 120px; }
}

@media (max-width: 480px) {
  .cards { grid-template-columns: 1fr; }
  h1 { font-size: 22px; }
  h3 { font-size: 15px; }
  .page-title p { font-size: 12px; }
}
