:root {
  --bg: #0f1720;
  --panel: #17212c;
  --panel-border: #263340;
  --text: #e7edf3;
  --muted: #90a4b7;
  --accent: #4fd1a5;
  --accent-dark: #2f9c78;
  --danger: #ef6f6f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

.screen { min-height: 100vh; }

/* Login */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 32px;
  width: 320px;
  text-align: center;
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.subtitle { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.login-card input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: #0d151d;
  color: var(--text);
}
.login-card button, .entry-form button {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #06261c;
  font-weight: 600;
  cursor: pointer;
}
.login-card button:hover, .entry-form button:hover { background: var(--accent-dark); }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; }

/* App layout: sidebar + main */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--panel-border);
}
.sidebar-title { font-weight: 700; letter-spacing: 0.04em; }
.sidebar-close-btn { display: none; }
.sidebar-nav { display: flex; flex-direction: column; padding: 12px; gap: 4px; }
.nav-item {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
}
.nav-item.active { background: var(--accent); color: #06261c; font-weight: 600; }
.nav-item.disabled { color: var(--muted); cursor: not-allowed; opacity: 0.55; }
.nav-subitem { padding-left: 28px; font-size: 13px; color: var(--muted); margin-top: -2px; }
.nav-subitem.active { color: #06261c; }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 20;
}

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

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}
.hamburger-btn { display: none; }

@media (max-width: 800px) {
  .hamburger-btn { display: inline-block; }
  .sidebar-close-btn { display: inline-block; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 21;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.hidden { display: none; }
}
@media (min-width: 801px) {
  .sidebar-backdrop { display: none !important; }
}

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--panel-border);
}
.topbar h1 { font-size: 18px; margin: 0; margin-right: auto; white-space: nowrap; }
.topbar-right { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.topbar-right input[type="month"],
.topbar-right select {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 8px;
}

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .topbar h1 { font-size: 16px; }
  .topbar-right { width: 100%; gap: 8px; }
  .topbar-right > * { flex: 1 1 auto; }
  .sync-status { display: none; } /* low-value clutter on a small screen */
}
.ghost-btn, .link-btn {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.link-btn { border: none; text-decoration: underline; padding: 0; }

.content { width: 100%; padding: 24px; max-width: 1100px; margin: 0 auto; box-sizing: border-box; }
@media (max-width: 640px) {
  .content { padding: 16px; }
}

/* Deliberate column counts per breakpoint rather than auto-fit, which packs in
   however many 185px slots happen to fit and can land on an awkward count
   (e.g. 3 cramped columns) at in-between widths like a tablet screen. */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
@media (max-width: 900px) {
  .kpi-row { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 640px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); gap: 8px; }
}
@media (max-width: 420px) {
  .kpi-row { grid-template-columns: 1fr; }
}

.kpi-row-secondary .kpi-tile { opacity: 0.85; }
.section-label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 0 0 8px; }
.kpi-tile {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 16px;
  min-width: 0;
}
.kpi-tile .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-tile .value {
  font-size: 20px;
  font-weight: 700;
  margin-top: 4px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}
.growth-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 6px;
  background: #0d151d;
  white-space: nowrap;
  flex-shrink: 0;
}
.growth-up { color: var(--accent); }
.growth-down { color: var(--danger); }

@media (max-width: 640px) {
  .kpi-tile { padding: 12px; }
  .kpi-tile .value { font-size: 17px; }
  .kpi-tile .label { font-size: 11px; }
}

.pcurrency-filter { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.pcurrency-filter-label { color: var(--muted); font-size: 13px; margin-right: 2px; }
.pcurrency-btn {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.pcurrency-btn:hover { color: var(--text); }
.pcurrency-btn.active { background: var(--accent); border-color: var(--accent); color: #06261c; }

.goal-section {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 20px;
}
.goal-header { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.goal-bar { background: #0d151d; border-radius: 6px; height: 10px; overflow: hidden; }
.goal-bar-fill { background: var(--accent); height: 100%; width: 0%; transition: width 0.4s ease; }
.goal-label { margin-top: 6px; font-size: 13px; color: var(--muted); }

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

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 20px;
}
.card h2 { font-size: 15px; margin: 0 0 12px; }

.trend-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.trend-header h2 { margin: 0; }
.trend-legend { display: flex; gap: 20px; flex-wrap: wrap; font-size: 13px; color: var(--text); }
.trend-legend .legend-item { display: flex; align-items: center; gap: 6px; }
.trend-legend .legend-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.trend-legend .legend-total { font-weight: 700; margin-left: 4px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--panel-border); }
th:first-child, td:first-child { text-align: left; }

.entry-form-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.entry-form-row label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
.entry-form-row input, .entry-form-row select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: #0d151d;
  color: var(--text);
  min-width: 140px;
}
.entry-form button { width: auto; padding: 10px 20px; display: inline-block; }
.saved-msg { color: var(--accent); margin-left: 12px; font-size: 13px; }
.product-section-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.product-section-header h2 { margin: 0; }
.product-section-total { font-weight: 700; font-size: 15px; }

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.product-card {
  background: #0d151d;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.product-card-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #1a2530 center/cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  position: relative;
}
.product-card-count {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--accent);
  color: #06261c;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}
.product-card-status {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(13, 21, 29, 0.85);
}
.product-card-status.active { color: var(--accent); border: 1px solid var(--accent); }
.product-card-status.inactive { color: #fff; background: var(--danger); border: 1px solid var(--danger); }
.product-card-body { padding: 10px 12px; }
.product-card-name { font-weight: 600; font-size: 14px; margin: 0 0 2px; }
.product-card-price { color: var(--muted); font-size: 12px; }
.product-card-price .amount { color: var(--muted); }
.product-grid-empty { color: var(--muted); font-size: 13px; }

.top-sellers { display: flex; flex-direction: column; gap: 20px; max-height: 460px; overflow-y: auto; }
.top-seller-group { display: flex; flex-direction: column; gap: 8px; }
.top-seller {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: #0d151d;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
}
.top-seller-rank { width: 24px; flex-shrink: 0; text-align: center; color: var(--muted); font-weight: 700; font-size: 13px; }
.top-seller-image {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: #1a2530 center/cover no-repeat;
  flex-shrink: 0;
}
.top-seller-body { min-width: 0; flex: 1; }
.top-seller-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.top-seller-name { font-weight: 700; font-size: 15px; margin: 2px 0; }
.top-seller-stat { font-size: 13px; color: var(--muted); }
.top-seller-stat strong { color: var(--text); }

.package-mix { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.package-mix-tile {
  background: #0d151d;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 14px;
}
.package-mix-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.package-mix-count { font-size: 20px; font-weight: 700; }
.package-mix-revenue { color: var(--muted); font-size: 13px; margin-top: 2px; }

.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.sync-status { color: var(--muted); font-size: 12px; }
.note-label { flex: 1; }
.note-label input { width: 100%; min-width: 0; }

.locations-body { display: flex; gap: 20px; align-items: stretch; }
.locations-map-wrap { flex: 1 1 60%; min-width: 0; background: #0d151d; border-radius: 8px; overflow: hidden; }
#locations-map { width: 100%; height: 360px; }
.locations-list { flex: 1 1 40%; min-width: 0; display: flex; flex-direction: column; }
.locations-list-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 4px 8px;
  border-bottom: 1px solid var(--panel-border);
}
.locations-table-body { display: flex; flex-direction: column; }
.location-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--panel-border); }
.location-row .location-bar-wrap { flex: 1; min-width: 0; position: relative; background: #0d151d; border-radius: 6px; overflow: hidden; }
.location-row .location-bar { background: rgba(79, 209, 165, 0.25); height: 100%; position: absolute; inset: 0 auto 0 0; border-radius: 6px; }
.location-row .location-name { position: relative; padding: 6px 10px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.location-row .location-views { font-size: 13px; font-weight: 600; flex-shrink: 0; min-width: 50px; text-align: right; }

/* jsvectormap theming: transparent background + dashboard colors instead of its own defaults */
.jvm-container { background: transparent !important; }
.jvm-tooltip {
  background: var(--panel) !important;
  border: 1px solid var(--panel-border) !important;
  color: var(--text) !important;
  font-size: 12px !important;
  padding: 4px 8px !important;
  border-radius: 6px !important;
}
.jvm-zoom-btn { background: var(--panel) !important; color: var(--text) !important; }

@media (max-width: 800px) {
  .locations-body { flex-direction: column; }
  #locations-map { height: 260px; }
}
