/* ============================================================
 * Thailand Automotive Collector v2.0 - common styles
 * ============================================================ */

:root {
  --primary: #1a56db;
  --primary-dark: #1e429f;
  --primary-light: #e8f0fe;
  --secondary: #6875f5;
  --success: #0e9f6e;
  --success-light: #def7ec;
  --warning: #c27803;
  --warning-light: #fdf6b2;
  --danger: #e02424;
  --danger-light: #fee2e2;
  --info: #0694a2;
  --info-light: #d5f5f6;
  --dark: #1f2937;
  --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;
  --white: #ffffff;
  --sidebar-width: 240px;
  --topbar-height: 64px;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.08), 0 4px 6px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  font-size: 14px;
  color: var(--gray-800);
  background: var(--gray-100);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; color: var(--gray-900); font-weight: 600; }
p  { margin: 0 0 8px; }

/* ============================================================
 * Layout
 * ============================================================ */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--dark);
  color: var(--white);
  position: fixed;
  top: 0; bottom: 0; left: 0;
  display: flex;
  flex-direction: column;
  z-index: 10;
  overflow-y: auto;
}
.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo {
  font-size: 18px; font-weight: 700; letter-spacing: .2px;
  display: flex; align-items: center; gap: 10px;
}
.sidebar-logo .fa-car { color: #60a5fa; }
.sidebar-subtitle {
  margin-top: 4px;
  font-size: 11px; color: #9ca3af;
}
.sidebar-section-title {
  padding: 12px 20px 6px;
  font-size: 10px; text-transform: uppercase;
  letter-spacing: .5px; color: #9ca3af;
}
.sidebar-nav { list-style: none; padding: 0; margin: 0; }
.sidebar-nav li a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; color: #d1d5db;
  font-size: 13px; font-weight: 500;
  border-left: 3px solid transparent;
  text-decoration: none;
  transition: background .15s, color .15s, border-color .15s;
}
.sidebar-nav li a:hover {
  background: rgba(255,255,255,.05);
  color: var(--white);
  text-decoration: none;
}
.sidebar-nav li a.active {
  background: rgba(26, 86, 219, .18);
  color: var(--white);
  border-left-color: #60a5fa;
}
.sidebar-nav li a i { width: 16px; text-align: center; color: inherit; }
.sidebar-nav-badge {
  margin-left: auto;
  background: var(--primary); color: #fff;
  font-size: 9px; font-weight: 700;
  padding: 2px 6px; border-radius: 999px;
  letter-spacing: .3px;
}
.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  font-size: 11px; color: #6b7280;
  border-top: 1px solid rgba(255,255,255,.05);
}

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-height);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-title { font-size: 16px; font-weight: 600; color: var(--gray-900); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

.page-content {
  padding: 24px;
  flex: 1;
}

/* ============================================================
 * Cards
 * ============================================================ */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; gap: 12px;
  font-weight: 600; color: var(--gray-900);
}
.card-header h3 { font-size: 14px; font-weight: 600; }
.card-header .spacer { flex: 1; }
.card-body { padding: 18px; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 960px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 18px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow-sm);
}
.stat-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--white);
  background: var(--primary);
  flex-shrink: 0;
}
.stat-icon.green   { background: var(--success); }
.stat-icon.orange  { background: #ea580c; }
.stat-icon.purple  { background: #7c3aed; }
.stat-icon.red     { background: var(--danger); }
.stat-icon.teal    { background: var(--info); }
.stat-icon.gray    { background: var(--gray-500); }

.stat-label { font-size: 11px; color: var(--gray-500); text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--gray-900); line-height: 1.1; }

/* ============================================================
 * Buttons
 * ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--gray-300);
  background: var(--white);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-700);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  text-decoration: none;
  line-height: 1.4;
}
.btn:hover  { background: var(--gray-100); text-decoration: none; }
.btn:active { background: var(--gray-200); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--primary); border-color: var(--primary); color: var(--white);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: var(--white); }
.btn-success:hover { background: #0b8a5f; }
.btn-danger  { background: var(--danger);  border-color: var(--danger);  color: var(--white); }
.btn-danger:hover  { background: #b91c1c; }
.btn-warning { background: var(--warning); border-color: var(--warning); color: var(--white); }
.btn-ghost   { background: transparent; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-xs { padding: 3px 7px; font-size: 11px; }
.btn-block { width: 100%; justify-content: center; }
.btn i { font-size: 12px; }

/* ============================================================
 * Forms
 * ============================================================ */
.form-group { margin-bottom: 12px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--gray-700); margin-bottom: 4px; }
.form-control,
.form-select,
.form-textarea {
  display: block; width: 100%;
  padding: 7px 10px;
  font-size: 13px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--gray-800);
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
.form-control:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,.15);
}
.form-textarea { min-height: 80px; resize: vertical; }
.form-help { font-size: 11px; color: var(--gray-500); margin-top: 3px; }

.filter-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 12px 16px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.filter-bar .form-control,
.filter-bar .form-select { width: auto; min-width: 140px; }
.filter-bar label { font-size: 12px; color: var(--gray-700); display: inline-flex; align-items: center; gap: 6px; }

/* ============================================================
 * Tables
 * ============================================================ */
.table-wrap { overflow-x: auto; border: 1px solid var(--gray-200); border-radius: var(--radius); background: var(--white); }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 700px;
}
table.data-table thead th {
  background: var(--gray-50);
  color: var(--gray-700);
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
table.data-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
table.data-table tbody tr:hover { background: var(--gray-50); }
table.data-table th.sortable { cursor: pointer; user-select: none; }
table.data-table th.sortable:hover { background: var(--gray-100); }
table.data-table th.sortable .sort-ind { color: var(--gray-400); font-size: 10px; margin-left: 4px; }

/* Pagination */
.pagination {
  display: flex; gap: 4px; align-items: center;
  padding: 12px; justify-content: flex-end;
}
.pagination .btn-sm { min-width: 32px; justify-content: center; }

/* ============================================================
 * Badges
 * ============================================================ */
.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  line-height: 1.5;
  white-space: nowrap;
}
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-green  { background: #dcfce7; color: #166534; }
.badge-gray   { background: var(--gray-200); color: var(--gray-700); }
.badge-teal   { background: var(--info-light); color: #036672; }
.badge-yellow { background: var(--warning-light); color: #713f12; }
.badge-red    { background: var(--danger-light); color: #991b1b; }

.conf-high   { background: #dcfce7; color: #166534; }
.conf-medium { background: #fef9c3; color: #713f12; }
.conf-low    { background: #fee2e2; color: #991b1b; }
.conf-review { background: #ffedd5; color: #9a3412; }

.pt-ice        { background: var(--gray-200); color: var(--gray-700); }
.pt-hev        { background: #dcfce7; color: #166534; }
.pt-series-hev { background: #ecfccb; color: #4d7c0f; }
.pt-phev       { background: #ccfbf1; color: #115e59; }
.pt-bev        { background: #ede9fe; color: #5b21b6; }

.tx-cvt  { background: #dbeafe; color: #1e40af; }
.tx-ecvt { background: #cffafe; color: #155e75; }
.tx-at   { background: #ffedd5; color: #9a3412; }
.tx-mt   { background: var(--gray-200); color: var(--gray-700); }

.status-completed { background: #dcfce7; color: #166534; }
.status-running   { background: #dbeafe; color: #1e40af; }
.status-queued    { background: #fef9c3; color: #713f12; }
.status-failed    { background: #fee2e2; color: #991b1b; }

/* URL link when broken */
a.url-broken {
  color: var(--danger) !important;
  text-decoration: line-through;
}
a.url-broken:hover { text-decoration: line-through underline; }

/* ============================================================
 * Toast Notifications
 * ============================================================ */
.toast-container {
  position: fixed;
  top: 20px; right: 20px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 12px 16px;
  min-width: 280px;
  max-width: 420px;
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--gray-400);
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 13px;
  animation: toast-in .25s ease-out;
}
.toast-success { border-left-color: var(--success); }
.toast-error   { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
.toast-info    { border-left-color: var(--info); }
.toast-icon { font-size: 16px; flex-shrink: 0; }
.toast-success .toast-icon { color: var(--success); }
.toast-error   .toast-icon { color: var(--danger); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info    .toast-icon { color: var(--info); }
.toast-message { flex: 1; color: var(--gray-800); line-height: 1.45; }
.toast-close {
  cursor: pointer;
  color: var(--gray-400);
  background: none; border: none;
  font-size: 16px; padding: 0;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ============================================================
 * Modal
 * ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(17, 24, 39, .55);
  display: none;
  align-items: center; justify-content: center;
  z-index: 9000;
  padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: modal-in .2s ease-out;
}
.modal.wide { max-width: 900px; }
.modal.xl   { max-width: 1100px; }
.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close {
  margin-left: auto;
  width: 28px; height: 28px;
  background: none; border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--gray-500);
  border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--gray-100); color: var(--gray-900); }
.modal-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--gray-200);
  display: flex; justify-content: flex-end; gap: 8px;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(-8px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
 * Misc
 * ============================================================ */
.hint-box {
  padding: 12px 14px;
  background: var(--primary-light);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  color: #1e3a8a;
  font-size: 12.5px;
  line-height: 1.55;
  margin-bottom: 16px;
}
.hint-box strong { color: #1e40af; }

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--gray-500);
}
.empty-state i { font-size: 34px; color: var(--gray-300); display: block; margin-bottom: 10px; }

.dropzone {
  padding: 36px 20px;
  text-align: center;
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  background: var(--gray-50);
  color: var(--gray-500);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.dropzone:hover,
.dropzone.drag-active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
}
.dropzone i { font-size: 32px; display: block; margin-bottom: 8px; }

/* Tabs */
.tab-bar { display: flex; gap: 2px; border-bottom: 1px solid var(--gray-200); margin-bottom: 14px; }
.tab-btn {
  padding: 8px 14px; font-size: 13px; font-weight: 500;
  background: none; border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  color: var(--gray-500);
}
.tab-btn:hover { color: var(--gray-800); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Checkboxes */
.check-group { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.check-group input[type="checkbox"] { width: 14px; height: 14px; cursor: pointer; accent-color: var(--primary); }

/* URL status icons inline */
.url-status-icon {
  display: inline-block;
  font-size: 13px;
  line-height: 1;
  vertical-align: middle;
}
.url-status-icon.ok     { color: var(--success); }
.url-status-icon.broken { color: var(--danger); }
.url-status-icon.redir  { color: #7c3aed; }

.text-muted { color: var(--gray-500); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mono { font-family: 'SF Mono', Menlo, Consolas, monospace; font-size: 12px; }

.flex-row { display: flex; gap: 8px; align-items: center; }
.flex-col { display: flex; flex-direction: column; gap: 8px; }

.link-cell a {
  font-size: 12px;
  word-break: break-all;
}

hr.soft { border: none; border-top: 1px solid var(--gray-200); margin: 14px 0; }
