/* =========================================================
   HUB — Central Reporting Dashboard · Dark Theme
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --surface:   #161b22;
  --surface2:  #1c2128;
  --border:    #30363d;
  --border2:   #21262d;
  --text:      #e6edf3;
  --text-dim:  #7d8590;
  --text-soft: #b1bac4;
  --blue:      #388bfd;
  --blue-dim:  #1f4080;
  --green:     #3fb950;
  --green-dim: #1a3a22;
  --yellow:    #d29922;
  --yellow-dim:#3a2d0a;
  --red:       #f85149;
  --red-dim:   #3d1c1c;
  --purple:    #bc8cff;
  --radius:    10px;
  --radius-sm: 6px;
}

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ---- Login ---- */
#loginScreen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.login-card .logo { font-size: 28px; font-weight: 700; letter-spacing: .5px; margin-bottom: 6px; }
.login-card .logo span { color: var(--text-dim); font-weight: 300; }
.login-card .sub { color: var(--text-dim); font-size: 13px; margin-bottom: 28px; }
.login-card input {
  width: 100%; padding: 12px 14px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; margin-bottom: 12px;
  font-family: monospace;
}
.login-card input:focus { outline: none; border-color: var(--blue); }
.login-error { color: var(--red); font-size: 12px; margin-bottom: 10px; min-height: 18px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); font-size: 13px; cursor: pointer;
  font-family: inherit; font-weight: 500;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--border2); border-color: var(--text-dim); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #4a9aff; }
.btn.danger { background: var(--red-dim); border-color: var(--red); color: var(--red); }
.btn.danger:hover { background: #5a2020; }
.btn.success { background: var(--green-dim); border-color: var(--green); color: var(--green); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface2); }
.btn.full { width: 100%; justify-content: center; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 5px 10px; font-size: 12px; }

/* ---- App Shell ---- */
#app { display: none; min-height: 100vh; flex-direction: column; }
#app.visible { display: flex; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex; align-items: center; gap: 16px;
  height: 56px; position: sticky; top: 0; z-index: 100;
}
.header-logo { font-size: 17px; font-weight: 700; letter-spacing: .3px; white-space: nowrap; }
.header-logo span { color: var(--text-dim); font-weight: 300; }
nav { display: flex; gap: 4px; flex: 1; }
.nav-btn {
  padding: 6px 14px; border-radius: var(--radius-sm);
  border: none; background: transparent; color: var(--text-dim);
  font-size: 13px; font-weight: 500; cursor: pointer;
  font-family: inherit; transition: color .15s, background .15s;
}
.nav-btn:hover { color: var(--text); background: var(--surface2); }
.nav-btn.active { color: var(--text); background: var(--surface2); }
.header-actions { display: flex; gap: 8px; margin-left: auto; }
.sync-all-btn { white-space: nowrap; }

main { flex: 1; padding: 24px 20px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* ---- Sections ---- */
.section { display: none; }
.section.active { display: block; }

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 10px;
}
.section-title { font-size: 18px; font-weight: 600; }

/* ---- System Cards Grid ---- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 16px;
}

.sys-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: border-color .2s;
}
.sys-card:hover { border-color: var(--text-dim); }
.sys-card.inactive { opacity: .5; }
.sys-card.status-error { border-color: var(--red); }
.sys-card.status-timeout { border-color: var(--yellow); }

.card-header {
  display: flex; align-items: center; gap: 10px; margin-bottom: 16px;
}
.platform-icon {
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.platform-icon.ebay    { background: linear-gradient(135deg,#e53238,#0064d2); }
.platform-icon.tiktok  { background: linear-gradient(135deg,#ff0050,#00f2ea); }
.platform-icon.kaufland{ background: #cc0000; }
.platform-icon.custom  { background: #1c2128; border: 1px solid var(--border); }

.card-name { font-size: 15px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-note { font-size: 11px; color: var(--text-dim); }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  margin-left: auto;
}
.status-dot.ok      { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.error   { background: var(--red); }
.status-dot.timeout { background: var(--yellow); }
.status-dot.never   { background: var(--text-dim); }

/* ---- Metrics Grid ---- */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.metric {
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.metric .lbl { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.metric .val { font-size: 18px; font-weight: 700; line-height: 1.1; }
.metric .val.green { color: var(--green); }
.metric .val.yellow { color: var(--yellow); }
.metric .val.red { color: var(--red); }
.metric .val.blue { color: var(--blue); }
.metric .val.dim { color: var(--text-dim); }

/* ---- Card Footer ---- */
.card-footer {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border2);
}
.card-footer .sync-info { font-size: 11px; color: var(--text-dim); flex: 1; }
.card-footer .sync-info .ok   { color: var(--green); }
.card-footer .sync-info .err  { color: var(--red); }
.card-footer .sync-info .warn { color: var(--yellow); }

.top-product {
  font-size: 11px; color: var(--text-soft);
  margin-bottom: 10px; padding: 6px 10px;
  background: var(--bg); border-radius: var(--radius-sm);
  border-left: 2px solid var(--blue);
}
.top-product strong { color: var(--text); }

.alert-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--red-dim); color: var(--red);
}

/* ---- Error State ---- */
.card-error {
  background: var(--red-dim); border-radius: var(--radius-sm);
  padding: 8px 12px; font-size: 12px; color: var(--red);
  margin-bottom: 10px; word-break: break-word;
}

/* ---- Alerts Section ---- */
.alert-list { display: flex; flex-direction: column; gap: 8px; }
.alert-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex; align-items: flex-start; gap: 12px;
}
.alert-item.sync_error { border-left: 3px solid var(--red); }
.alert-item.system_alert { border-left: 3px solid var(--yellow); }
.alert-item.no_data { border-left: 3px solid var(--text-dim); }
.alert-icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.alert-body { flex: 1; }
.alert-system { font-weight: 600; font-size: 13px; }
.alert-msg { color: var(--text-soft); font-size: 12px; margin-top: 2px; }
.alert-since { color: var(--text-dim); font-size: 11px; margin-top: 4px; }
.no-alerts {
  text-align: center; padding: 48px 24px;
  color: var(--text-dim); font-size: 14px;
}
.no-alerts .icon { font-size: 40px; margin-bottom: 12px; }

/* ---- Admin Section ---- */
.admin-layout { display: grid; grid-template-columns: 1fr 400px; gap: 20px; }
@media (max-width: 900px) { .admin-layout { grid-template-columns: 1fr; } }

.card-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-box h3 { font-size: 15px; font-weight: 600; margin-bottom: 16px; }

/* ---- System Table ---- */
.sys-table { width: 100%; border-collapse: collapse; }
.sys-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-dim); padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.sys-table td { padding: 10px 10px; border-bottom: 1px solid var(--border2); vertical-align: middle; }
.sys-table tr:last-child td { border-bottom: none; }
.sys-table tr:hover td { background: var(--surface2); }
.sys-table .name-cell { font-weight: 500; }
.sys-table .url-cell { font-size: 11px; color: var(--text-dim); font-family: monospace; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sys-table .actions-cell { display: flex; gap: 4px; justify-content: flex-end; }

/* ---- Form ---- */
.form-field { margin-bottom: 14px; }
.form-field label { display: block; font-size: 12px; font-weight: 500; color: var(--text-soft); margin-bottom: 5px; }
.form-field input, .form-field select, .form-field textarea {
  width: 100%; padding: 9px 12px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; font-family: inherit;
}
.form-field input:focus, .form-field select:focus {
  outline: none; border-color: var(--blue);
}
.form-field select { cursor: pointer; }
.form-field small { font-size: 11px; color: var(--text-dim); margin-top: 4px; display: block; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-msg { font-size: 12px; margin-top: 10px; min-height: 18px; }
.form-msg.ok { color: var(--green); }
.form-msg.err { color: var(--red); }

/* ---- Badge ---- */
.badge {
  display: inline-block; padding: 2px 8px;
  border-radius: 999px; font-size: 11px; font-weight: 600;
}
.badge.active { background: var(--green-dim); color: var(--green); }
.badge.inactive { background: var(--border); color: var(--text-dim); }
.badge.ok { background: var(--green-dim); color: var(--green); }
.badge.error { background: var(--red-dim); color: var(--red); }
.badge.timeout { background: var(--yellow-dim); color: var(--yellow); }
.badge.never { background: var(--border); color: var(--text-dim); }

/* ---- Loading / Empty ---- */
.loading { text-align: center; padding: 60px 24px; color: var(--text-dim); }
.empty-state { text-align: center; padding: 60px 24px; color: var(--text-dim); }
.empty-state .icon { font-size: 40px; margin-bottom: 12px; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 18px;
  font-size: 13px; color: var(--text);
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
  transform: translateY(80px); opacity: 0;
  transition: transform .3s, opacity .3s;
  z-index: 999; max-width: 340px;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.ok  { border-left: 3px solid var(--green); }
.toast.err { border-left: 3px solid var(--red); }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ---- Responsive ---- */
@media (max-width: 600px) {
  .cards-grid { grid-template-columns: 1fr; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  header { padding: 0 14px; gap: 10px; }
  main { padding: 16px 14px; }
  .header-logo { font-size: 15px; }
}

/* ---- Spinner ---- */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 14px; height: 14px; border: 2px solid var(--border);
  border-top-color: var(--blue); border-radius: 50%;
  animation: spin .8s linear infinite; display: inline-block;
}

/* ---- Stats Bar ---- */
.stats-bar {
  display: flex; gap: 16px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.stat-chip {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 16px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat-chip .lbl { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }
.stat-chip .val { font-size: 22px; font-weight: 700; }
.stat-chip .val.green { color: var(--green); }
.stat-chip .val.blue  { color: var(--blue); }
.stat-chip .val.red   { color: var(--red); }
