*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }

:root {
  --crimson: #990033;
  --gold: #cfa75e;
  --green: #1a7a4a;
  --red: #cc2200;
  --amber: #c9920a;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-muted: #6b7280;
  --text-subtle: #999999;
  --crimson-soft: rgba(153, 0, 51, 0.08);
  --gold-soft: rgba(207, 167, 94, 0.16);
  --green-soft: rgba(26, 122, 74, 0.14);
  --red-soft: rgba(204, 34, 0, 0.12);
  --amber-soft: rgba(201, 146, 10, 0.14);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --ease: 0.2s ease;
  --header-height: 88px;
}

body {
  font-family: 'Poppins', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--crimson);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

input, select, textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: #fff;
  padding: 0.75rem 0.95rem;
  transition: border-color var(--ease), box-shadow var(--ease), background-color var(--ease);
}

textarea {
  resize: vertical;
}

input:focus, select:focus, textarea:focus, button:focus {
  outline: 2px solid rgba(153, 0, 51, 0.22);
  outline-offset: 2px;
  border-color: var(--crimson);
}

.site-header {
  background: var(--crimson);
  color: #fff;
  min-height: var(--header-height);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 60;
}

.brand-lockup {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-wordmark {
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.05em;
  font-size: 1.4rem;
  line-height: 1;
}

.brand-subtitle {
  color: var(--gold);
  font-weight: 500;
  font-size: 0.8rem;
  line-height: 1.25;
  margin-top: 0.28rem;
}

.header-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
}

.live-dot {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  background: var(--amber);
  display: inline-block;
  animation: pulse-amber 1.6s infinite;
  flex-shrink: 0;
}

.live-indicator.live .live-dot {
  background: var(--green);
  animation: pulse-green 1.6s infinite;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
  padding: 0.5rem 0.85rem;
  border-radius: 999px;
  background: rgba(255,255,255,0.14);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 500;
}

.header-btn {
  min-height: 44px;
  padding: 0.65rem 0.95rem;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-weight: 600;
  transition: background-color var(--ease), border-color var(--ease);
}

.header-btn:hover {
  background: rgba(255,255,255,0.16);
  border-color: rgba(255,255,255,0.28);
  text-decoration: none;
}

.app-shell[hidden],
.auth-shell[hidden] {
  display: none !important;
}

.tab-nav {
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 0;
  overflow-x: auto;
  position: sticky;
  top: var(--header-height);
  z-index: 50;
  box-shadow: var(--shadow-sm);
  scrollbar-width: none;
}

.tab-nav::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  min-height: 56px;
  padding: 0 1.15rem;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  white-space: nowrap;
  transition: color var(--ease), border-color var(--ease), background-color var(--ease);
}

.tab-btn:hover {
  color: var(--text);
  background: rgba(17,24,39,0.03);
}

.tab-btn.active {
  color: var(--crimson);
  border-bottom-color: var(--crimson);
}

main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.5rem;
}

.page {
  display: none;
  animation: fade-up 0.22s ease;
}

.page.active {
  display: block;
}

.page-head {
  margin-bottom: 1.2rem;
}

.page-head h1 {
  margin: 0;
  font-size: 1.7rem;
  line-height: 1.2;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.page-head h1 i {
  color: var(--crimson);
  font-size: 1.1rem;
}

.page-head p {
  margin: 0.45rem 0 0;
  color: var(--text-muted);
  font-size: 15px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card + .card {
  margin-top: 1rem;
}

.card-header {
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.card-title-icon {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: var(--crimson-soft);
  color: var(--crimson);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.card-title h2 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.25;
}

.card-title p {
  margin: 0.18rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.card-body {
  padding: 1.2rem;
}

.section-stack {
  display: grid;
  gap: 1rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.kpi-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.kpi-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--crimson-soft);
  color: var(--crimson);
  font-size: 1rem;
  margin-bottom: 0.1rem;
}

.kpi-card.gold .kpi-icon {
  background: var(--gold-soft);
  color: #7c5d20;
}

.kpi-card.green .kpi-icon {
  background: var(--green-soft);
  color: var(--green);
}

.kpi-value {
  font-size: 2rem;
  line-height: 1;
  font-weight: 800;
  min-height: 32px;
  color: var(--text);
}

.kpi-label {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.stat-inline {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.mini-stat {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.85rem 0.9rem;
  background: #fff;
  min-width: 160px;
}

.mini-stat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
}

.mini-stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 0.18rem;
}

.chart-shell {
  position: relative;
  height: 380px;
}

.deadline-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.deadline-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
  padding: 0.9rem 1rem;
}

.deadline-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.45;
  color: var(--text);
}

.deadline-meta {
  margin-top: 0.55rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0.3rem 0.72rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
}

.badge-crimson {
  background: var(--crimson-soft);
  color: var(--crimson);
  border: 1px solid rgba(153,0,51,0.18);
}

.badge-gold {
  background: var(--gold-soft);
  color: #7c5d20;
  border: 1px solid rgba(207,167,94,0.3);
}

.badge-green {
  background: var(--green-soft);
  color: var(--green);
  border: 1px solid rgba(26,122,74,0.2);
}

.badge-red {
  background: var(--red-soft);
  color: var(--red);
  border: 1px solid rgba(204,34,0,0.18);
}

.badge-amber {
  background: var(--amber-soft);
  color: var(--amber);
  border: 1px solid rgba(201,146,10,0.2);
}

.badge-grey {
  background: #eff1f4;
  color: #5b6572;
  border: 1px solid #d8dde4;
}

.btn {
  min-height: 44px;
  padding: 0.65rem 0.95rem;
  border-radius: 12px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.1;
  transition: background-color var(--ease), border-color var(--ease), color var(--ease), opacity var(--ease);
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--crimson);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #7b0029;
  text-decoration: none;
}

.btn-outline {
  background: #fff;
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--crimson);
  color: var(--crimson);
  text-decoration: none;
}

.btn-success {
  background: var(--green);
  color: #fff;
}

.btn-success:hover:not(:disabled) {
  background: #16673f;
  text-decoration: none;
}

.btn-danger {
  background: #fff;
  color: var(--red);
  border-color: rgba(204,34,0,0.2);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(204,34,0,0.04);
  text-decoration: none;
}

.btn-gold {
  background: var(--gold);
  color: #3d2a00;
}

.btn-gold:hover:not(:disabled) {
  background: #ba944d;
  text-decoration: none;
}

.filter-grid,
.form-grid,
.team-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.filter-grid.filter-grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.field-group.full-span {
  grid-column: 1 / -1;
}

.field-group label {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.field-hint {
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.validation-error {
  display: none;
  color: #b00020;
  font-size: 0.9rem;
  line-height: 1.45;
}

.validation-error.visible {
  display: block;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #fff;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control label {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 0.8rem;
  border-right: 1px solid var(--border);
  font-weight: 600;
  cursor: pointer;
  background: #fff;
  transition: background-color var(--ease), color var(--ease);
}

.segmented-control label:last-child {
  border-right: none;
}

.segmented-control input:checked + label {
  background: var(--crimson);
  color: #fff;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1020px;
  background: #fff;
}

thead th {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 10;
  height: 52px;
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
  text-align: left;
  white-space: nowrap;
}

tbody td {
  border-bottom: 1px solid var(--border);
  padding: 0.95rem 1rem;
  vertical-align: top;
  font-size: 15px;
  line-height: 1.5;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover td {
  background: rgba(153,0,51,0.025);
}

.sort-btn {
  width: 100%;
  min-height: 44px;
  border: none;
  padding: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  text-align: left;
}

.sort-btn:hover {
  color: var(--crimson);
}

.sort-btn.sort-asc::after {
  content: '^';
  color: var(--crimson);
}

.sort-btn.sort-desc::after {
  content: 'v';
  color: var(--crimson);
}

.table-title {
  font-weight: 600;
  color: var(--text);
}

.table-subtext {
  margin-top: 0.22rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.action-btns {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.info-card {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.1rem;
}

.info-card p {
  margin: 0;
  font-size: 15px;
  color: var(--text);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  text-align: center;
  padding: 3rem 1.25rem;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 2.4rem;
  color: #cad0d8;
}

.empty-state h3 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--text);
}

.empty-state p {
  margin: 0;
  max-width: 380px;
  font-size: 15px;
}

.json-textarea {
  min-height: 220px;
  font-family: "Courier New", monospace;
  font-size: 14px;
  line-height: 1.55;
}

.alert {
  border-radius: var(--radius-md);
  padding: 0.9rem 1rem;
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 1rem;
}

.alert-error {
  background: rgba(204,34,0,0.07);
  border: 1px solid rgba(204,34,0,0.16);
  color: #8f2100;
}

.alert-success {
  background: rgba(26,122,74,0.08);
  border: 1px solid rgba(26,122,74,0.16);
  color: #16673f;
}

.preview-tools {
  margin-top: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.preview-options {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
  font-weight: 500;
  color: var(--text);
}

.check-row input {
  width: 18px;
  min-height: auto;
  margin: 0;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(17,24,39,0.48);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 90;
}

.modal.open {
  display: flex;
}

.modal-dialog {
  width: min(860px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border-radius: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.modal-header {
  padding: 1.15rem 1.2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.3;
}

.modal-header p {
  margin: 0.3rem 0 0;
  color: var(--text-muted);
  font-size: 15px;
}

.modal-body {
  padding: 1.2rem;
}

.modal-footer {
  padding: 1rem 1.2rem 1.2rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.modal-close {
  width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.modal-close:hover {
  border-color: var(--crimson);
  color: var(--crimson);
}

.summary-list {
  display: grid;
  gap: 0.75rem;
}

.summary-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.85rem 0.95rem;
  background: #fff;
}

.summary-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.summary-meta {
  margin-top: 0.35rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.toast-container {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  z-index: 95;
  max-width: min(380px, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  border-radius: 999px;
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow-sm);
  color: #fff;
  font-weight: 600;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity var(--ease), transform var(--ease);
  pointer-events: auto;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-success {
  background: var(--green);
}

.toast-error {
  background: var(--red);
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(153,0,51,0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 100;
}

.spinner {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: 4px solid rgba(255,255,255,0.24);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}

.loading-label {
  color: #fff;
  font-size: 1rem;
  font-weight: 500;
}

.auth-shell {
  max-width: 760px;
  margin: 2rem auto 0;
  padding: 0 1rem 2rem;
}

.auth-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.auth-top {
  padding: 1.35rem 1.4rem;
  border-bottom: 1px solid var(--border);
  background: rgba(153,0,51,0.03);
}

.auth-top h1 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.2;
  color: var(--text);
}

.auth-top p {
  margin: 0.45rem 0 0;
  color: var(--text-muted);
  font-size: 15px;
}

.auth-body {
  padding: 1.35rem 1.4rem 1.45rem;
}

.auth-actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.auth-note {
  margin-top: 1rem;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.site-footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-subtle);
  padding: 1.5rem;
}

.series-steps {
  display: grid;
  gap: 0.85rem;
}

.step-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
  background: #fff;
}

.step-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.step-title {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text);
}

.step-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.step-grid .full-span {
  grid-column: 1 / -1;
}

.pill-note {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 32px;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: #f0f2f5;
  color: #59636f;
}

.small-muted {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.hidden {
  display: none !important;
}

body.modal-open {
  overflow: hidden;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse-green {
  0% { transform: scale(0.95); opacity: 0.85; }
  50% { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.85; }
}

@keyframes pulse-amber {
  0% { transform: scale(0.95); opacity: 0.82; }
  50% { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.82; }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1180px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .kpi-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-grid.filter-grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  :root {
    --header-height: 96px;
  }

  .site-header {
    padding: 0.95rem 1rem;
    align-items: flex-start;
  }

  .header-tools {
    width: 100%;
    justify-content: flex-start;
  }

  main {
    padding: 1rem;
  }

  .kpi-strip,
  .filter-grid,
  .filter-grid.filter-grid-4,
  .form-grid,
  .team-grid,
  .step-grid {
    grid-template-columns: 1fr;
  }

  .step-grid .full-span {
    grid-column: auto;
  }
}

@media (max-width: 520px) {
  .kpi-strip {
    grid-template-columns: 1fr;
  }

  .tab-btn {
    padding: 0 0.9rem;
  }
}
