:root {
  --green: #17a453;
  --green-dark: #0f7439;
  --black: #101214;
  --ink: #1b1e20;
  --muted: #6f7375;
  --line: #e2e4e5;
  --paper: #ffffff;
  --soft: #f3f4f4;
  --gray: #7c7c7a;
  --orange: #ff5f1f;
  --orange-dark: #d94a12;
  --yellow: #ffb01f;
  --danger: #c7372f;
  --shadow: 0 18px 50px rgba(17, 20, 18, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Roboto, Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--soft);
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(16, 18, 20, 0.96), rgba(84, 84, 82, 0.88), rgba(255, 95, 31, 0.72)),
    url("data:image/svg+xml,%3Csvg width='900' height='540' viewBox='0 0 900 540' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.16'%3E%3Cpath d='M-30 470 C170 310 330 520 530 330 S790 180 950 310'/%3E%3Cpath d='M-20 210 C120 80 300 250 450 140 S740 40 930 170'/%3E%3Cpath d='M80 560 L840 -20'/%3E%3Cpath d='M-70 120 L340 530'/%3E%3C/g%3E%3C/svg%3E");
  background-size: cover;
}

.login-panel {
  width: min(100%, 430px);
  padding: 34px;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.brand-logo {
  display: block;
  object-fit: contain;
}

.login-logo {
  width: min(100%, 310px);
  height: auto;
  margin-bottom: 18px;
}

.sidebar-logo {
  width: 184px;
  height: auto;
}

.eyebrow {
  margin: 18px 0 8px;
  color: var(--orange);
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 32px; line-height: 1.1; margin-bottom: 10px; color: var(--black); }
h2 { font-size: 28px; margin-bottom: 0; color: var(--black); }
h3 { font-size: 18px; margin-bottom: 18px; color: var(--black); }

.login-copy { color: var(--muted); line-height: 1.5; }

.login-form, .data-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 13px;
  background: #fff;
  color: var(--black);
  min-height: 44px;
}

input:focus, select:focus {
  outline: 3px solid rgba(255, 95, 31, 0.18);
  border-color: var(--orange);
}

.primary-action, .secondary-action, .ghost-action, .icon-action {
  border: 0;
  border-radius: 6px;
  min-height: 42px;
  font-weight: 800;
}

.primary-action {
  background: var(--orange);
  color: #fff;
  padding: 0 18px;
}

.secondary-action {
  background: var(--black);
  color: #fff;
  padding: 0 14px;
  font-size: 13px;
}

.ghost-action {
  width: 100%;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.icon-action {
  min-width: 36px;
  padding: 0 10px;
  color: var(--black);
  background: var(--gray);
}

.icon-action.danger { color: #fff; background: var(--danger); }
.form-error { color: var(--danger); min-height: 18px; margin: 0; font-weight: 700; }

.link-action {
  border: 0;
  background: transparent;
  color: var(--orange);
  font-weight: 800;
  min-height: 42px;
  padding: 0;
  text-align: left;
}

.register-form {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.form-message { color: var(--green-dark); min-height: 18px; margin: 0; font-weight: 700; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px 1fr;
}

.app-shell.tv-mode {
  grid-template-columns: 1fr;
}

.app-shell.tv-mode .sidebar {
  display: none;
}

.app-shell.tv-mode .workspace {
  padding: 18px;
}

.app-shell.tv-mode .hero-chart canvas {
  height: 520px;
}

.app-shell.tv-mode .dashboard-grid {
  grid-template-columns: 1.45fr 0.75fr;
}

.app-shell.tv-mode #exportPdfBtn,
.app-shell.tv-mode #exportExcelBtn {
  display: none;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  background: linear-gradient(180deg, #101214 0%, #242628 62%, #ff5f1f 170%);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.sidebar-brand {
  min-height: 66px;
  display: flex;
  align-items: center;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  min-height: 44px;
  text-align: left;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  color: #dce6df;
  background: transparent;
  font-weight: 800;
}

.nav-item.active, .nav-item:hover {
  background: var(--orange);
  color: #fff;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.tv-mode-action {
  white-space: nowrap;
  background: var(--orange);
}

.topbar .eyebrow { margin-top: 0; }

.topbar-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
  width: min(100%, 700px);
}

.view { display: none; }
.active-view { display: grid; gap: 18px; }

.goal-banner {
  display: none;
  padding: 16px 18px;
  border-radius: 8px;
  color: #fff;
  background: var(--green);
  font-weight: 900;
  box-shadow: var(--shadow);
}

.goal-banner.show { display: block; }
.goal-banner.alert { background: var(--orange); color: var(--black); }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.tv-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.tv-card {
  min-height: 132px;
  padding: 18px;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, #101214 0%, #2a2d30 58%, #ff5f1f 165%);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.tv-card span,
.tv-card small {
  display: block;
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.tv-card strong {
  display: block;
  margin: 12px 0 7px;
  font-size: clamp(23px, 2.35vw, 38px);
  line-height: 1;
  color: #fff;
  overflow-wrap: anywhere;
}

.pulse-card {
  background: linear-gradient(135deg, #ff5f1f 0%, #d94a12 62%, #101214 150%);
}

.metric-card, .panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 26px rgba(17, 20, 18, 0.05);
}

.metric-card {
  min-height: 118px;
  padding: 18px;
  border-top: 5px solid var(--orange);
}

.metric-card.warning { border-top-color: var(--orange); }
.metric-card.success { border-top-color: var(--green); }

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.metric-card strong {
  display: block;
  color: var(--black);
  font-size: clamp(19px, 1.85vw, 26px);
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.goal-breakdown-panel {
  padding: 16px 18px;
}

.goal-breakdown-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.goal-breakdown-card {
  min-height: 96px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fff 0%, #f7f8f8 100%);
  border-top: 4px solid #cfd7d1;
}

.goal-breakdown-card.active {
  border-top-color: var(--orange);
  box-shadow: 0 10px 22px rgba(255, 95, 31, 0.12);
}

.goal-breakdown-card span,
.goal-breakdown-card small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.goal-breakdown-card strong {
  display: block;
  margin: 8px 0 7px;
  color: var(--black);
  font-size: clamp(19px, 1.8vw, 28px);
  line-height: 1;
}

.goal-breakdown-card small {
  color: var(--green-dark);
  text-transform: none;
}

.seller-goal-panel {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 18px;
  align-items: stretch;
  margin: 18px 0;
  padding: 18px;
  border-radius: 8px;
  background: linear-gradient(135deg, #11161b 0%, #2f2826 58%, #873a1f 100%);
  color: #fff;
  box-shadow: var(--shadow);
}

.seller-goal-panel[hidden] {
  display: none;
}

.seller-goal-title {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  border-right: 1px solid rgba(255, 255, 255, 0.18);
}

.seller-goal-title span,
.seller-goal-metrics span {
  color: #d7dde2;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.seller-goal-title strong {
  font-size: clamp(25px, 2.7vw, 42px);
  line-height: 1;
}

.seller-goal-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 14px;
}

.seller-goal-metrics div {
  min-height: 88px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.seller-goal-metrics strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(22px, 2.1vw, 34px);
  line-height: 1;
}

.seller-goal-complete {
  background: linear-gradient(135deg, #0f7a3a 0%, #11161b 58%, #ff5f1f 100%);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 18px;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel.wide { grid-column: span 1; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h3 { margin-bottom: 0; }

.panel-subtitle {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.hero-chart {
  overflow: hidden;
}

.hero-chart.dark-chart {
  background: #101418;
  border-color: #1e252b;
}

.hero-chart.dark-chart h3 {
  color: #fff;
}

.hero-chart.dark-chart .panel-subtitle {
  color: #aeb8c2;
}

.compact-select {
  width: 190px;
  min-height: 38px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 800;
}

.tv-sector-select {
  width: 210px;
  border: 2px solid #ff5f1f;
  background: #fff7f2;
  color: #111412;
  font-size: 14px;
}

canvas {
  width: 100%;
  max-width: 100%;
  height: 300px;
  display: block;
  image-rendering: auto;
}

#dailyChart {
  cursor: crosshair;
}

.hero-chart canvas {
  height: 390px;
}

.ranking-list {
  display: grid;
  gap: 10px;
}

.summary-list {
  display: grid;
  gap: 12px;
}

.summary-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(90deg, #ffffff 0%, #f7f8f8 100%);
}

.summary-row strong,
.summary-row span,
.summary-row small {
  display: block;
}

.summary-row strong {
  color: var(--black);
  font-size: 16px;
}

.summary-row span {
  color: var(--orange-dark);
  font-weight: 900;
  font-size: 18px;
}

.summary-row small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.summary-missing {
  color: var(--danger) !important;
}

.rank-row {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.rank-position {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--gray);
  font-weight: 900;
}

.rank-row.top-1 .rank-position { background: var(--yellow); }
.rank-row.top-2 .rank-position { background: #cfd7d1; }
.rank-row.top-3 .rank-position { background: #e7a46d; }
.rank-row strong, .rank-row span { display: block; }
.rank-row span { color: var(--muted); font-size: 12px; margin-top: 4px; }
.rank-value { font-weight: 900; color: var(--green-dark); text-align: right; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(112px, 1fr));
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.calendar-day, .calendar-weekday {
  min-height: 100px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 10px;
  background: #fff;
}

.calendar-weekday {
  min-height: 38px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--gray);
  font-size: 12px;
  font-weight: 900;
}

.calendar-day.empty { background: transparent; border-style: dashed; }
.calendar-day.above { border-left: 5px solid var(--green); }
.calendar-day.below { border-left: 5px solid var(--orange); }
.calendar-day strong { display: block; font-size: 16px; color: var(--black); }
.calendar-day span { display: block; margin-top: 8px; color: var(--muted); font-size: 12px; }
.calendar-day b { display: block; margin-top: 6px; color: var(--orange-dark); font-size: 13px; }
.calendar-legend { color: var(--muted); font-size: 13px; }

.form-panel { max-width: 980px; }

.data-form {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  align-items: end;
}

.full-field { grid-column: span 2; }

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th, td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.actions-cell {
  display: flex;
  gap: 8px;
}

@media (max-width: 1180px) {
  .metrics-grid { grid-template-columns: repeat(3, 1fr); }
  .seller-goal-panel { grid-template-columns: 1fr; }
  .seller-goal-title { border-right: 0; border-bottom: 1px solid rgba(255, 255, 255, 0.18); padding-bottom: 14px; }
  .seller-goal-metrics { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
  .goal-breakdown-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tv-strip { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
  }
  .nav-list { grid-template-columns: repeat(4, 1fr); }
  .topbar { align-items: stretch; flex-direction: column; }
  .topbar-actions { grid-template-columns: repeat(2, 1fr); width: 100%; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .tv-strip { grid-template-columns: repeat(2, 1fr); }
  .data-form { grid-template-columns: 1fr; }
  .full-field { grid-column: auto; }
}

@media (max-width: 580px) {
  .workspace { padding: 16px; }
  .login-panel { padding: 24px; }
  h1 { font-size: 26px; }
  h2 { font-size: 23px; }
  .nav-list { grid-template-columns: 1fr 1fr; }
  .topbar-actions, .metrics-grid, .seller-goal-metrics, .goal-breakdown-list, .tv-strip { grid-template-columns: 1fr; }
  .panel-head { align-items: stretch; flex-direction: column; }
  .rank-row { grid-template-columns: 38px 1fr; }
  .rank-value { grid-column: 2; text-align: left; }
}

@media print {
  .sidebar, .topbar-actions, .secondary-action, .ghost-action, .admin-only { display: none !important; }
  .app-shell { display: block; }
  .workspace { padding: 0; }
  .panel, .metric-card { box-shadow: none; break-inside: avoid; }
}
