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

:root {
  --bg: #0f0f0f;
  --surface: #181818;
  --border: #272727;
  --text: #e0e0e0;
  --muted: #666;
  --accent: #fff;
}

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

.hidden { display: none !important; }

/* ── Login ── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 320px;
}

.login-logo {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 20px;
}

.login-card h1 {
  font-size: 22px;
  font-weight: 500;
  margin-bottom: 24px;
}

.login-card input[type="password"] {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  margin-bottom: 10px;
  transition: border-color 0.15s;
}

.login-card input[type="password"]:focus { border-color: #444; }

.login-card button[type="submit"] {
  width: 100%;
  padding: 9px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

.login-card button[type="submit"]:hover { opacity: 0.85; }

.error { color: #e05555; font-size: 12px; margin-top: 10px; }

/* ── App shell ── */
.app { display: flex; flex-direction: column; min-height: 100vh; }

.header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  height: 52px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 20;
}

.header-logo {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  margin-right: 4px;
}

.top-nav { display: flex; gap: 2px; flex: 1; }

.top-tab {
  padding: 5px 14px;
  border: none;
  border-radius: 5px;
  background: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.top-tab:hover { color: var(--text); }
.top-tab.active { background: var(--surface); color: var(--text); }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #c0392b;
  color: #fff;
  border-radius: 10px;
  font-size: 10px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  margin-left: 4px;
  vertical-align: middle;
}

.cat-bar {
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  background: var(--bg);
}

.tabs { display: flex; gap: 2px; padding: 8px 0; }

.tab {
  padding: 5px 12px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  text-transform: capitalize;
}

.tab:hover { color: var(--text); }

.tab.active {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

/* ── Views ── */
.view { display: flex; flex-direction: column; flex: 1; }

.btn-ghost {
  padding: 5px 12px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-ghost:hover { color: var(--text); border-color: #444; }

/* ── Main ── */
.main {
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  width: 100%;
}

/* ── Upload zone ── */
.upload-zone {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  margin-bottom: 20px;
  transition: border-color 0.15s, background 0.15s;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: #444;
  background: rgba(255,255,255,0.015);
}

.upload-arrow { font-size: 24px; color: var(--muted); margin-bottom: 6px; }
.upload-idle p { color: var(--muted); }
.underline { color: var(--text); text-decoration: underline; cursor: pointer; }

.progress-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 10px;
  max-width: 300px;
  margin-left: auto;
  margin-right: auto;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0;
  transition: width 0.2s;
}

.progress-label { color: var(--muted); }

/* ── Grid header ── */
.grid-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.muted { color: var(--muted); }
.hint { font-size: 12px; }

/* ── Image grid ── */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  grid-auto-flow: row;
  gap: 10px;
}

.img-card {
  position: relative;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
  cursor: grab;
  user-select: none;
}

.img-card:active { cursor: grabbing; }

.img-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  border: none;
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.img-card:hover .delete-btn { opacity: 1; }
.delete-btn:hover { background: rgba(180,40,40,0.8); }

.rename-btn {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  border: none;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.img-card:hover .rename-btn { opacity: 1; }

.download-btn {
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.img-card:hover .download-btn { opacity: 1; }

.img-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px 8px;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  font-size: 11px;
  color: #ccc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.15s;
}

.img-card:hover .img-name { opacity: 1; }

.sortable-ghost { opacity: 0.25; }
.sortable-chosen { box-shadow: 0 0 0 2px rgba(255,255,255,0.25); border-radius: 6px; }

/* ── Analytics ── */
.analytics-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.analytics-header h2 { font-size: 16px; font-weight: 500; }

.day-btns { display: flex; gap: 4px; }
.day-btn {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.day-btn.active { background: var(--surface); color: var(--text); border-color: #444; }

.stat-card-row { display: flex; gap: 12px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  min-width: 140px;
}
.stat-number { font-size: 28px; font-weight: 500; }
.stat-label { color: var(--muted); font-size: 12px; margin-top: 2px; }

.chart-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 24px;
  height: 220px;
}

.analytics-tables { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.analytics-table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.analytics-table h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 12px; }
.analytics-table table { width: 100%; border-collapse: collapse; font-size: 12px; }
.analytics-table td { padding: 5px 0; color: var(--text); }
.analytics-table td:last-child { text-align: right; color: var(--muted); }

/* ── Messages ── */
#view-messages h2 { font-size: 16px; font-weight: 500; margin-bottom: 20px; }

.messages-list { display: flex; flex-direction: column; gap: 10px; }

.msg-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  transition: border-color 0.15s;
}
.msg-card.unread { border-color: #444; }
.msg-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--muted);
}
.msg-sender { font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 4px; }
.msg-email { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.msg-body { font-size: 13px; line-height: 1.6; white-space: pre-wrap; color: var(--text); }
.msg-read-btn {
  margin-top: 10px;
  padding: 4px 10px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}
.msg-read-btn:hover { color: var(--text); }
.msg-empty { color: var(--muted); font-size: 13px; }
