/* ── Apple Design System ───────────────────────────────
   Color palette inspired by Apple's design language
   Background: #f5f5f7  |  Text: #1d1d1f
   Secondary: #86868b    |  Accent: #0071e3
   Border: #d2d2d7       |  Card: #ffffff
*/

:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --text-secondary: #86868b;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --border: #d2d2d7;
  --sidebar-bg: #ffffff;
  --sidebar-width: 240px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 2px 12px rgba(0,0,0,0.08);
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
               "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── Sidebar Layout ──────────────────────────────── */

.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-header {
  padding: 28px 20px 20px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.sidebar-logo {
  width: 48px; height: 48px;
  margin: 0 auto 10px;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
}
.sidebar-logo.is-text {
  background: var(--accent);
  color: #fff;
}
.sidebar-logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }

.sidebar-company {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
}
.nav-item:hover { background: rgba(0,0,0,0.04); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item .bi { font-size: 18px; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.sidebar-user-icon {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}
.sidebar-user-name { font-weight: 500; color: var(--text); }
.sidebar-user-role { font-size: 11px; color: var(--text-secondary); }
.sidebar-logout {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 12px;
  transition: color 0.15s;
}
.sidebar-logout:hover { color: var(--accent); }

.site-filing {
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.7;
  text-align: center;
}
.site-filing a {
  color: var(--text-secondary);
  text-decoration: none;
}
.site-filing a:hover {
  color: var(--accent);
  text-decoration: underline;
}
.sidebar-filing {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* Mobile sidebar toggle */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 200;
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: var(--card);
  border: 1px solid var(--border);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ── Main Content Area ──────────────────────────── */

.main-content {
  margin-left: var(--sidebar-width);
  padding: 32px 40px;
  max-width: 1400px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--text);
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 4px 0 0;
}

/* ── Cards ──────────────────────────────────────── */

.app-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}
.app-card-body { padding: 20px 24px; }
.app-card-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 15px;
}

/* ── Stats / Progress Card ─────────────────────── */

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 20px;
  border: 1px solid var(--border);
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.progress {
  height: 8px;
  border-radius: 4px;
  background: #e8e8ed;
  overflow: hidden;
}
.progress-bar {
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* ── Tables ──────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
}

table.app-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.app-table th {
  text-align: left;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.app-table td {
  padding: 12px 16px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}

.app-table tr:last-child td { border-bottom: none; }
.app-table tr:hover td { background: rgba(0,113,227,0.03); }

/* ── Buttons ────────────────────────────────────── */

.btn-app {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  line-height: 1.4;
}

.btn-app-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-app-primary:hover { background: var(--accent-hover); }

.btn-app-secondary {
  background: var(--card);
  color: var(--text);
  border-color: var(--border);
}
.btn-app-secondary:hover { background: #f5f5f7; }

.btn-app-success {
  background: #28a745;
  color: #fff;
}

.btn-app-danger {
  background: #dc3545;
  color: #fff;
}
.btn-app-danger-outline {
  background: transparent;
  color: #dc3545;
  border-color: #dc3545;
}

.btn-app-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-app-lg {
  padding: 12px 24px;
  font-size: 15px;
}

/* ── Forms ────────────────────────────────────────── */

.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--card);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,113,227,0.15);
}

.form-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ── Status Badges ──────────────────────────────── */

.badge-app {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-draft { background: #e8e8ed; color: #6e6e73; }
.badge-progress { background: #e8f0fe; color: var(--accent); }
.badge-done { background: #e6f7e6; color: #28a745; }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-info { background: #e8f0fe; color: var(--accent); }

/* ── Alerts ──────────────────────────────────────── */

.alert-app {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  border-left: 3px solid;
}
.alert-success { background: #e6f7e6; border-color: #28a745; color: #1a7a1a; }
.alert-danger  { background: #fde8e8; border-color: #dc3545; color: #a71d2a; }
.alert-warning { background: #fff3cd; border-color: #ffc107; color: #856404; }
.alert-info    { background: #e8f0fe; border-color: var(--accent); color: #0056a3; }

/* ── Grid helpers ────────────────────────────────── */

.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.text-muted { color: var(--text-secondary); }
.text-sm { font-size: 12px; }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 16px; }

/* ── Login Page ────────────────────────────────── */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f5f7 0%, #e8e8ed 100%);
  padding: 64px 20px 88px;
  position: relative;
}

.login-filing {
  position: absolute;
  right: 20px;
  bottom: 16px;
  left: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  padding: 40px 36px 32px;
}

.login-logo {
  width: 56px; height: 56px;
  border-radius: 14px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  overflow: hidden;
}
.login-logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.login-logo span { width:100%; height:100%; display:flex; align-items:center; justify-content:center; background:var(--accent); }

.login-title {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 28px;
}

.login-card .form-input {
  padding: 12px 14px;
  font-size: 15px;
}

.login-btn {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.login-btn:hover { background: var(--accent-hover); }

/* ── Scanner Page ───────────────────────────────── */

.scanner-container {
  max-width: 420px;
  margin: 0 auto;
}
.scanner-container video {
  border-radius: var(--radius);
  width: 100%;
}

/* ── Label Print Preview ───────────────────────── */

.label-page { padding: 0; margin: 0; background: #f0f0f0; }
.print-toolbar {
  position: fixed;
  top: 0; left: var(--sidebar-width); right: 0;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
}

@media print {
  .sidebar, .sidebar-toggle, .print-toolbar { display: none !important; }
  .main-content { margin-left: 0 !important; padding: 0 !important; }
  .label-grid { margin-top: 0; gap: 0; }
  .label { border: none; page-break-after: always; }
}

/* ── Responsive ────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; }
  .main-content {
    margin-left: 0;
    padding: 60px 16px 24px;
  }
  .page-title { font-size: 22px; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .print-toolbar { left: 0; }
  .label-page .main-content { padding: 0; }
}

/* ── Animations ────────────────────────────────── */

.fade-in { animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ── File upload area ─────────────────────────── */

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  background: #fafafa;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: #f0f5ff;
}
.upload-zone-icon { font-size: 32px; color: var(--text-secondary); margin-bottom: 8px; }
.upload-zone-text { font-size: 14px; color: var(--text); }
.upload-zone-hint { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* ── Order cards on scanner select page ──────── */

.order-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  transition: box-shadow 0.2s;
  cursor: pointer;
}
.order-card:hover { box-shadow: var(--shadow-md); }
.order-card-title { font-size: 16px; font-weight: 600; }
.order-card-meta { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.order-card-progress { margin-top: 12px; }

/* ── Logo preview ─────────────────────────────── */

.logo-preview {
  width: 80px; height: 80px;
  border-radius: 14px;
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f7;
}
.logo-preview img { width: 100%; height: 100%; object-fit: contain; }
.logo-preview.empty { font-size: 24px; color: var(--text-secondary); }

/* ── Mobile touch-friendly ── */
@media (max-width: 768px) {
  .btn-app { padding: 10px 18px; font-size: 14px; min-height: 44px; }
  .btn-app-sm { padding: 6px 12px; font-size: 12px; min-height: 32px; }
  .form-input, .form-select, .form-textarea { padding: 12px 14px; font-size: 16px; }
  .app-card-body { padding: 16px; }
  .page-header { flex-direction: column; gap: 12px; }
  .page-title { font-size: 22px; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  .table-wrap { border-radius: 8px; }
  .app-table th, .app-table td { padding: 10px 12px; font-size: 12px; }
}

/* Inline edit */
.editable { cursor: pointer; position: relative; }
.editable:hover { background: rgba(0,113,227,0.05) !important; }
.editable:hover::after { content: "✎"; position:absolute; right:4px; top:2px; font-size:11px; color:var(--accent); opacity:0.5; }
.inline-edit-input { width:100%; padding:3px 6px; border:1px solid var(--accent); border-radius:4px; font-size:13px; }

/* ── Table dark header ── */
.app-table thead.table-dark {
  --bs-table-bg: #f5f5f7;
  --bs-table-color: var(--text-secondary);
  --bs-table-border-color: var(--border);
  background: #f5f5f7;
}
.app-table thead.table-dark tr {
  background: #f5f5f7;
}
.app-table thead.table-dark th {
  background: #f5f5f7;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 11px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.02em;
}
.app-table thead.table-dark th .text-muted {
  color: var(--text-secondary) !important;
  font-weight: 400;
}

/* ── Page Header Bar ──────────────────────────── */
.page-header-bar {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}
.page-header-bar .header-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}
.page-header-bar .header-sub {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.page-header-bar .header-meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
}
.page-header-bar .header-actions {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
