/* ── Theme ─────────────────────────────────────────────────────────────────── */
:root {
  --bg:       #f7f7f8;
  --surface:  #ffffff;
  --text:     #111111;
  --text-2:   #555555;
  --text-3:   #999999;
  --border:   #e4e4e7;
  --border-2: #f0f0f0;
  --hover:    #f4f4f5;
  --accent:   #5b5bd6;
  --accent-s: #eeeeff;
  --accent-t: #3d3db4;
  --red:      #e5484d;
  --red-s:    #fff0f0;
  --green:    #30a46c;
  --amber:    #f59e0b;
  --input-bg: var(--bg);
  --sh: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
}

[data-theme="dark"] {
  --bg:       #0f0f10;
  --surface:  #1a1a1c;
  --text:     #eeeeee;
  --text-2:   #a0a0a8;
  --text-3:   #606068;
  --border:   #2a2a2e;
  --border-2: #222224;
  --hover:    #242428;
  --accent:   #7c7cf0;
  --accent-s: #1c1c3a;
  --accent-t: #a0a0f8;
  --red:      #f27474;
  --red-s:    #2a1212;
  --green:    #4cc38a;
  --amber:    #fbbf24;
  --input-bg: #222224;
  --sh: 0 1px 3px rgba(0,0,0,.35);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: .75rem;
  gap: .75rem;
  transition: background .2s, color .2s;
}

/* ── Nav ───────────────────────────────────────────────────────────────────── */
.topnav {
  width: 100%; max-width: 860px;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--sh);
  overflow: hidden;
}

.nav-links {
  display: flex; align-items: center; gap: .1rem;
  padding: .4rem .65rem;
  border-bottom: 1px solid var(--border-2);
}

.nav-stats {
  display: flex; align-items: center; gap: .5rem;
  padding: .35rem .75rem;
  background: var(--hover);
}

.nav-link {
  text-decoration: none;
  color: var(--text-2);
  font-size: .85rem; font-weight: 500;
  padding: .28rem .55rem; border-radius: 7px;
  border: none; background: none;
  cursor: pointer; font-family: inherit;
  transition: background .1s, color .1s;
  white-space: nowrap;
}
.nav-link:hover         { background: var(--hover); color: var(--text); }
.nav-link--active       { background: var(--accent-s); color: var(--accent); }
.nav-link--active:hover { background: var(--accent-s); color: var(--accent-t); }
.nav-link--muted        { color: var(--text-3); margin-left: auto; }

@media (max-width: 560px) {
  .nav-links {
    flex-wrap: wrap;
    gap: .2rem;
    padding: .45rem .5rem;
  }
  .nav-link {
    flex: 0 0 calc(33.333% - .14rem);
    text-align: center;
    font-size: .78rem;
    padding: .32rem .2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .nav-link--muted { margin-left: 0; }
}

.stat-chip {
  font-size: .75rem; font-weight: 600;
  color: var(--text-3); white-space: nowrap;
  padding: .18rem .55rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
}

/* keep old .user-count for any leftover usage */
.user-count { display: none; }

.theme-toggle {
  font-size: .8rem; width: 1.65rem; height: 1.65rem;
  padding: 0; border-radius: 8px;
  background: none; border: 1px solid var(--border);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--text-2); transition: background .1s; flex-shrink: 0;
  margin-left: auto;
}
.theme-toggle:hover { background: var(--surface); }

/* ── Card ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: 12px;
  padding: 1.75rem 1.5rem;
  width: 100%; max-width: 440px;
  border: 1px solid var(--border);
  box-shadow: var(--sh);
}
.page-wrap { max-width: 860px; }

/* ── Typography ────────────────────────────────────────────────────────────── */
h1 {
  font-size: 1.2rem; font-weight: 700;
  letter-spacing: -.015em;
  margin-bottom: .2rem;
}
.subtitle { color: var(--text-3); font-size: .875rem; margin-bottom: 1.25rem; }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
label {
  display: flex; flex-direction: column; gap: .35rem;
  font-size: .85rem; font-weight: 500;
  color: var(--text-2); margin-bottom: .875rem;
}
.hint { font-weight: 400; color: var(--text-3); font-size: .78rem; }

input[type="text"], input[type="password"], input[type="date"],
textarea, select {
  width: 100%; padding: .6rem .875rem;
  font-size: .9375rem;
  border: 1px solid var(--border); border-radius: 8px;
  outline: none; color: var(--text);
  background: var(--input-bg); font-family: inherit;
  transition: border-color .12s, background .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent); background: var(--surface);
}
select { cursor: pointer; }
textarea { resize: vertical; min-height: 100px; }

.file-label input[type="file"] {
  padding: .55rem;
  border: 1.5px dashed var(--border);
  border-radius: 8px; background: var(--input-bg);
  color: var(--text-2); cursor: pointer; font-size: .85rem;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
button, .btn {
  display: block; width: 100%;
  padding: .65rem .875rem;
  font-size: .9375rem; font-weight: 600;
  background: var(--accent); color: #fff;
  border: none; border-radius: 8px;
  cursor: pointer; text-align: center;
  text-decoration: none; margin-top: .4rem;
  font-family: inherit; letter-spacing: -.005em;
  transition: filter .1s;
}
button:hover, .btn:hover { filter: brightness(1.1); }
button:active, .btn:active { filter: brightness(.92); }

.btn--sm {
  width: auto; padding: .32rem .7rem;
  font-size: .8125rem; border-radius: 7px;
  display: inline-block; margin-top: 0;
  white-space: nowrap; flex-shrink: 0;
}
.btn--outline {
  background: transparent; color: var(--accent);
  border: 1px solid var(--accent);
}
.btn--outline:hover { filter: none; background: var(--accent-s); }

.btn-icon {
  background: none; border: none;
  cursor: pointer; font-size: 1rem;
  padding: .28rem .4rem; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  width: auto; margin: 0;
  color: var(--text-3); transition: background .1s;
  text-decoration: none;
}
.btn-icon:hover { background: var(--hover); color: var(--text); }

.btn-icon--danger {
  font-size: .79rem; font-weight: 600;
  color: var(--red); border: 1px solid var(--border);
  border-radius: 6px; padding: .28rem .55rem;
}
.btn-icon--danger:hover { background: var(--red-s); border-color: var(--red); }

.btn-clear {
  width: auto; padding: .42rem .72rem;
  font-size: .79rem; border-radius: 7px;
  background: transparent; color: var(--text-3);
  border: 1px solid var(--border);
  margin-top: 0; white-space: nowrap;
  cursor: pointer; font-family: inherit;
  transition: background .1s, color .1s;
}
.btn-clear:hover { background: var(--hover); color: var(--text); }

/* ── Alerts ────────────────────────────────────────────────────────────────── */
.error {
  background: var(--red-s); color: var(--red);
  border: 1px solid color-mix(in srgb, var(--red) 25%, transparent);
  border-radius: 8px; padding: .6rem .875rem;
  font-size: .875rem; margin-bottom: .875rem;
}
.logout {
  display: block; text-align: center;
  margin-top: 1.25rem; color: var(--text-3);
  font-size: .85rem; text-decoration: none;
}
.logout:hover { color: var(--text-2); }

/* ── Success page ──────────────────────────────────────────────────────────── */
.card--success { text-align: center; padding-top: 2.5rem; }
.checkmark { font-size: 2.5rem; color: var(--green); margin-bottom: .75rem; }
.device-name { color: var(--text-3); font-size: .9rem; margin: .5rem 0 1.5rem; }

/* ── List header ───────────────────────────────────────────────────────────── */
.list-header {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

/* ── Brand pills ───────────────────────────────────────────────────────────── */
.brand-pills {
  display: flex; gap: .3rem;
  overflow-x: auto; padding-bottom: .25rem;
  margin-bottom: .875rem;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.brand-pills::-webkit-scrollbar { display: none; }

.brand-pill {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .28rem .7rem;
  font-size: .79rem; font-weight: 600;
  border: 1px solid var(--border); border-radius: 20px;
  background: var(--surface); color: var(--text-2);
  cursor: pointer; white-space: nowrap;
  font-family: inherit; width: auto; margin: 0; line-height: 1;
  transition: background .1s, border-color .1s;
  -webkit-tap-highlight-color: transparent;
}
.brand-pill:hover          { border-color: var(--accent); color: var(--accent); background: var(--accent-s); }
.brand-pill:active         { opacity: .75; }
.brand-pill--active        { background: var(--accent); border-color: var(--accent); color: #fff; }
.brand-pill--active:hover  { filter: brightness(1.08); background: var(--accent); color: #fff; }

.pill-count {
  font-size: .65rem; font-weight: 700;
  background: rgba(0,0,0,.12);
  padding: .07rem .32rem; border-radius: 10px; line-height: 1.5;
}
.brand-pill--active .pill-count { background: rgba(255,255,255,.28); }

/* ── Brand section ─────────────────────────────────────────────────────────── */
.brand-section { margin-bottom: 1.1rem; }

.brand-section-header {
  display: flex; align-items: center; gap: .5rem;
  padding: .35rem .5rem;
  border-radius: 7px; margin-bottom: .4rem;
}
.brand-section-title {
  font-size: .75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-3); flex: 1;
}
.brand-section-meta { font-size: .73rem; color: var(--text-3); white-space: nowrap; }

/* ── Search ────────────────────────────────────────────────────────────────── */
.search-input {
  width: 100%; padding: .58rem .875rem;
  font-size: .9rem; border: 1px solid var(--border);
  border-radius: 8px; outline: none;
  background: var(--input-bg); color: var(--text);
  font-family: inherit; margin-bottom: 1rem;
  transition: border-color .12s;
}
.search-input:focus         { border-color: var(--accent); background: var(--surface); }
.search-input--inline       { flex: 1; margin-bottom: 0; }

/* ── Device block ──────────────────────────────────────────────────────────── */
.device-block {
  border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden;
  margin-bottom: .65rem; background: var(--surface);
}
.device-header {
  display: flex; align-items: center; gap: .5rem;
  padding: .58rem .875rem;
  background: var(--hover);
  border-bottom: 1px solid var(--border-2);
}
.device-title {
  font-weight: 600; font-size: .875rem;
  color: var(--text); flex: 1;
  min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

/* ── Badges ────────────────────────────────────────────────────────────────── */
.promo-badge {
  background: var(--accent-s); color: var(--accent);
  font-size: .72rem; font-weight: 700;
  padding: .1rem .42rem; border-radius: 10px; flex-shrink: 0;
}
.brand-badge {
  background: rgba(48,164,108,.12); color: var(--green);
  font-size: .7rem; font-weight: 600;
  padding: .1rem .42rem; border-radius: 10px; flex-shrink: 0;
}
.expires-badge { color: var(--amber); font-weight: 600; }

/* ── Promo card ────────────────────────────────────────────────────────────── */
.promo-card {
  display: flex; align-items: flex-start; gap: .65rem;
  padding: .65rem .875rem;
  border-bottom: 1px solid var(--border-2);
  background: var(--surface);
}
.promo-card:last-child { border-bottom: none; }

.promo-thumbs {
  display: flex; gap: .3rem; flex-shrink: 0;
  overflow-x: auto; max-width: 148px;
  scrollbar-width: none; align-items: flex-start;
}
.promo-thumbs::-webkit-scrollbar { display: none; }

.promo-thumb {
  width: 58px; height: 58px;
  object-fit: cover; border-radius: 7px;
  flex-shrink: 0; background: var(--hover);
}
.promo-thumb--placeholder {
  width: 58px; height: 58px;
  border-radius: 7px; flex-shrink: 0;
  background: var(--hover);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
}
.promo-info { flex: 1; min-width: 0; }
.promo-desc {
  font-size: .83rem; color: var(--text-2);
  display: -webkit-box; -webkit-line-clamp: 3;
  -webkit-box-orient: vertical; overflow: hidden;
  line-height: 1.45; margin-bottom: .2rem;
}
.promo-date { font-size: .73rem; color: var(--text-3); }

.promo-actions {
  display: flex; flex-direction: column;
  gap: .2rem; flex-shrink: 0;
}
.promo-actions form { margin: 0; }

.no-promos  { padding: .65rem .875rem; color: var(--text-3); font-size: .85rem; }
.empty-state { color: var(--text-3); padding: 1.5rem 0; text-align: center; font-size: .9rem; }
.empty-state a { color: var(--accent); }

/* ── Date row ──────────────────────────────────────────────────────────────── */
.date-row { display: flex; gap: .4rem; align-items: center; }
.date-row input[type="date"] { flex: 1; margin-bottom: 0; }

/* ── Autocomplete ──────────────────────────────────────────────────────────── */
.ac-wrap { position: relative; }
.ac-list {
  position: absolute; z-index: 200;
  top: calc(100% + 2px); left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 10px; max-height: 220px;
  overflow-y: auto; list-style: none;
  padding: .25rem 0;
  box-shadow: 0 6px 20px rgba(0,0,0,.12);
}
.ac-list li {
  padding: .58rem .875rem; cursor: pointer;
  font-size: .9rem; color: var(--text);
  border-bottom: 1px solid var(--border-2);
}
.ac-list li:last-child { border-bottom: none; }
.ac-list li:hover { background: var(--accent-s); color: var(--accent-t); }

/* ── Brand management ──────────────────────────────────────────────────────── */
.brand-add-row { display: flex; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.brand-add-input { flex: 1; margin-bottom: 0 !important; }

.mgmt-list  { display: flex; flex-direction: column; gap: .35rem; }
.mgmt-row   { border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: var(--surface); }
.mgmt-view  { display: flex; align-items: center; gap: .4rem; padding: .58rem .875rem; }
.mgmt-name  { flex: 1; font-size: .875rem; font-weight: 600; color: var(--text); }
.mgmt-meta  { font-size: .73rem; color: var(--text-3); white-space: nowrap; }
.mgmt-edit  { padding: .58rem .875rem; background: var(--hover); border-top: 1px solid var(--border-2); }
.mgmt-edit-form { display: flex; gap: .4rem; align-items: center; }
.brand-edit-input {
  flex: 1; padding: .5rem .75rem;
  font-size: .875rem;
  border: 1.5px solid var(--accent); border-radius: 7px;
  background: var(--surface); color: var(--text);
  font-family: inherit; outline: none; margin: 0;
}

/* ── Edit page ─────────────────────────────────────────────────────────────── */
.edit-section { margin-bottom: 1.5rem; padding-bottom: 1.25rem; border-bottom: 1px solid var(--border-2); }
.section-label {
  font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3); margin-bottom: .75rem;
}
.photo-grid { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .875rem; }
.photo-grid-item { position: relative; width: 76px; height: 76px; flex-shrink: 0; }
.photo-grid-img  {
  width: 76px; height: 76px; object-fit: cover;
  border-radius: 8px; display: block; background: var(--hover);
}
.photo-grid-placeholder { display: flex; align-items: center; justify-content: center; font-size: 1.5rem; }
.photo-cover-label {
  position: absolute; bottom: 4px; left: 4px;
  font-size: .54rem; font-weight: 700; text-transform: uppercase;
  background: rgba(0,0,0,.5); color: #fff;
  padding: 1px 4px; border-radius: 3px; pointer-events: none;
}
.photo-del-btn {
  position: absolute; top: -5px; right: -5px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--red); color: #fff; border: none;
  font-size: 13px; line-height: 1;
  cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  padding: 0; margin: 0;
}
.photo-del-btn:hover { filter: brightness(1.15); background: var(--red); }
.photo-dl-btn {
  position: absolute; top: -5px; left: -5px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: .7rem; font-weight: 700; line-height: 18px;
  text-align: center; text-decoration: none; display: block;
}
.photo-dl-btn:hover { filter: brightness(1.15); }

.current-photo     { margin-bottom: 1rem; border-radius: 10px; overflow: hidden; }
.current-photo-img { width: 100%; max-height: 220px; object-fit: cover; display: block; border-radius: 10px; }

/* ── Stats table ────────────────────────────────────────────────────────────── */
.stats-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.stats-table th {
  text-align: left; padding: .5rem .75rem;
  border-bottom: 2px solid var(--border);
  color: var(--text-2); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em;
}
.stats-table td { padding: .55rem .75rem; border-bottom: 1px solid var(--border-2); }
.stats-table tr:last-child td { border-bottom: none; }
.stats-section-row td {
  background: var(--hover); color: var(--text-2);
  font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  padding: .4rem .75rem;
}
.stats-val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.stats-val--warn { color: var(--amber); }
