:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --sidebar: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #2563eb;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
}

.hidden { display: none !important; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo h1 { font-size: 24px; margin-top: 12px; }
.login-logo p { color: var(--text-muted); font-size: 13px; }

.logo-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px; height: 48px;
  background: var(--primary);
  color: #fff;
  border-radius: 12px;
  font-size: 22px;
  font-weight: 700;
}
.logo-icon.sm { width: 36px; height: 36px; font-size: 16px; border-radius: 8px; }

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

.sidebar {
  width: 240px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand strong { color: #fff; display: block; font-size: 15px; }
.sidebar-brand small { font-size: 11px; opacity: .7; }

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  border: none;
  background: none;
  color: var(--sidebar-text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 2px;
  transition: background .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar h2 { font-size: 20px; font-weight: 600; }

.content { flex: 1; padding: 24px; overflow-y: auto; }

/* Banner */
.banner {
  margin: 0 24px;
  padding: 12px 16px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}
.banner-warning { background: var(--warning-bg); color: #92400e; border: 1px solid #fcd34d; }

/* Cards & stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.stat-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat-card .sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.panel-header h3 { font-size: 15px; font-weight: 600; }
.panel-body { padding: 20px; }

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

/* Forms */
label { display: block; margin-bottom: 14px; font-size: 13px; font-weight: 500; }
input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
textarea { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { color: var(--danger); font-size: 12px; margin: 8px 0; padding: 8px 12px; background: var(--danger-bg); border-radius: 6px; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
  align-items: flex-end;
}
.filters label { margin: 0; flex: 1; min-width: 140px; }
.filters input, .filters select { margin-top: 4px; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--bg); font-weight: 600; font-size: 12px; color: var(--text-muted); white-space: nowrap; }
tr:hover td { background: #fafbfc; }
td.actions { white-space: nowrap; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-neutral { background: #f1f5f9; color: var(--text-muted); }
.badge-primary { background: #dbeafe; color: var(--primary); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal.modal-lg { max-width: 820px; }
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { font-size: 16px; }
.modal-close {
  background: none; border: none; font-size: 22px;
  cursor: pointer; color: var(--text-muted); line-height: 1;
  padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--surface);
  border-radius: 0 0 12px 12px;
  position: sticky;
  bottom: 0;
}

/* Toast */
#toast-container { position: fixed; top: 16px; right: 16px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: slideIn .2s ease;
  max-width: 360px;
}
.toast-success { background: var(--success-bg); color: #166534; border: 1px solid #86efac; }
.toast-error { background: var(--danger-bg); color: #991b1b; border: 1px solid #fca5a5; }
.toast-info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Lists */
.file-list { list-style: none; margin-top: 8px; }
.file-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px; background: var(--bg); border-radius: 6px; margin-bottom: 4px; font-size: 12px;
}
.file-list .remove-file { color: var(--danger); cursor: pointer; border: none; background: none; font-size: 16px; }

.company-check-list {
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
}
.company-check-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.company-check-item:hover { background: var(--bg); }
.company-check-item input { width: auto; margin: 0; }

.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.story-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.story-card.add-card {
  display: flex; align-items: center; justify-content: center;
  min-height: 180px; border-style: dashed; cursor: pointer;
  color: var(--text-muted); font-size: 14px;
}
.story-card.add-card:hover { border-color: var(--primary); color: var(--primary); }
.story-card img { width: 100%; height: 120px; object-fit: cover; background: var(--bg); }
.story-card-body { padding: 12px; }
.story-card-body h4 { font-size: 14px; margin-bottom: 4px; }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state p { margin-top: 8px; font-size: 13px; }

.rec-list { list-style: none; }
.rec-list li {
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  border-left: 3px solid var(--primary);
}

.check-list { list-style: none; }
.check-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.check-ok { color: var(--success); font-weight: 600; }
.check-fail { color: var(--danger); font-weight: 600; }
.check-unknown { color: var(--text-muted); }

.brand-bar { margin-bottom: 6px; }
.brand-bar-label { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 2px; }
.brand-bar-track { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.brand-bar-fill { height: 100%; background: var(--primary); border-radius: 3px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }

.preview-block {
  background: var(--bg);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  font-size: 13px;
}
.preview-block strong { display: block; margin-bottom: 4px; color: var(--primary); }

.selected-count { font-size: 12px; color: var(--text-muted); }

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color .15s;
}
.upload-zone:hover { border-color: var(--primary); }
.upload-zone input { display: none; }
