/* ============================================================
   THEME.CSS - Dark Editorial Theme
   Wuji Operations Daily Report BI Dashboard
   ============================================================ */

/* --- CSS Variables --- */
:root {
  --bg-0: #0D0C0A;
  --bg-1: #141310;
  --bg-2: #1C1A15;
  --bg-3: #252218;
  --ink-hi: #F4EEDD;
  --ink: #D9CFB8;
  --ink-lo: #8A8269;
  --ink-mute: #5A533F;
  --ink-dim: #3A3428;
  --line: rgba(244,238,221,0.06);
  --line-hi: rgba(244,238,221,0.10);
  --accent: #D4845A;
  --accent-lo: rgba(212,132,90,0.12);
  --accent-hi: #E8996E;
  --flow: #7AA8FF;
  --flow-lo: rgba(122,168,255,0.10);
  --ok: #8BC99A;
  --warn: #E5B054;
  --err: #E27771;
  --font-serif: 'Instrument Serif', Georgia, serif;
  --font-sans: 'Inter', 'Noto Sans SC', 'PingFang SC', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --transition: 0.2s ease;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-0);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-0);
}

::-webkit-scrollbar-thumb {
  background: var(--ink-dim);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--ink-mute);
}

/* --- Selection --- */
::selection {
  background: var(--accent-lo);
  color: var(--ink-hi);
}

/* --- Links --- */
a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--accent-hi);
}

/* ============================================================
   LAYOUT
   ============================================================ */

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  width: 100%;
}

/* --- Masthead --- */
.mast {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(13,12,10,0.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mast-logo {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  color: var(--ink-hi);
  letter-spacing: -0.02em;
}

.mast-logo .dot {
  color: var(--accent);
}

.mast-nav {
  display: flex;
  align-items: center;
  gap: 24px;
}

.mast-nav a {
  color: var(--ink-lo);
  font-size: 0.875rem;
  font-weight: 500;
  transition: color var(--transition);
}

.mast-nav a:hover,
.mast-nav a.active {
  color: var(--ink-hi);
}

.mast-version {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-mute);
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
}

/* --- Sidebar --- */
.sidebar {
  position: fixed;
  top: 56px;
  left: 0;
  bottom: 0;
  width: 260px;
  background: var(--bg-1);
  border-right: 1px solid var(--line);
  padding: 24px 0;
  overflow-y: auto;
  z-index: 90;
  transition: transform 0.3s ease;
}

.sidebar.collapsed {
  transform: translateX(-260px);
}

.sidebar-header {
  padding: 0 20px 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.sidebar-section {
  padding: 8px 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-mute);
}

/* --- Nav Items --- */
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: var(--ink-lo);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition);
  border-radius: 0;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--bg-2);
  color: var(--ink);
}

.nav-item.active {
  color: var(--accent);
  background: var(--accent-lo);
  border-right: 2px solid var(--accent);
}

.nav-item .icon {
  width: 18px;
  height: 18px;
  opacity: 0.7;
}

/* --- Main Content --- */
.main-content {
  margin-left: 260px;
  padding: 32px 32px 64px;
  min-height: calc(100vh - 56px);
  transition: margin-left 0.3s ease;
}

.main-content.expanded {
  margin-left: 0;
}

/* ============================================================
   CARDS
   ============================================================ */

.card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  transition: all var(--transition);
}

.card:hover {
  border-color: var(--line-hi);
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  color: var(--ink-hi);
}

/* --- Stat Cards --- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all var(--transition);
}

.stat-card:hover {
  border-color: var(--line-hi);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.stat-card .stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-lo);
}

.stat-card .stat-value {
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--ink-hi);
  line-height: 1.2;
}

.stat-card .stat-trend {
  font-size: 0.75rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat-card .stat-trend.up {
  color: var(--ok);
}

.stat-card .stat-trend.down {
  color: var(--err);
}

/* ============================================================
   DATA TABLE
   ============================================================ */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table thead {
  position: sticky;
  top: 0;
  background: var(--bg-2);
  z-index: 2;
}

.data-table th {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-lo);
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line-hi);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background var(--transition);
}

.data-table tbody tr:hover {
  background: var(--bg-2);
}

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

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

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

.btn-primary:hover {
  background: var(--accent-hi);
  border-color: var(--accent-hi);
  box-shadow: 0 4px 12px rgba(212,132,90,0.3);
}

.btn-secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--line-hi);
}

.btn-secondary:hover {
  background: var(--bg-2);
  border-color: var(--ink-mute);
  color: var(--ink-hi);
}

.btn-danger {
  background: transparent;
  color: var(--err);
  border-color: var(--err);
}

.btn-danger:hover {
  background: rgba(226,119,113,0.1);
  box-shadow: 0 4px 12px rgba(226,119,113,0.2);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.75rem;
  border-radius: 6px;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ============================================================
   BADGES
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 100px;
  letter-spacing: 0.02em;
}

.badge-submitted {
  background: var(--flow-lo);
  color: var(--flow);
}

.badge-approved {
  background: rgba(139,201,154,0.12);
  color: var(--ok);
}

.badge-rejected {
  background: rgba(226,119,113,0.12);
  color: var(--err);
}

.badge-pending {
  background: rgba(229,176,84,0.12);
  color: var(--warn);
}

/* ============================================================
   FORM ELEMENTS
   ============================================================ */

.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-lo);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 14px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--ink-hi);
  background: var(--bg-2);
  border: 1px solid var(--line-hi);
  border-radius: var(--radius);
  outline: none;
  transition: all var(--transition);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-lo);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--ink-mute);
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10L6 8z' fill='%238A8269'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

.form-select option {
  background: var(--bg-2);
  color: var(--ink);
}

.form-textarea {
  min-height: 100px;
  resize: vertical;
}

/* ============================================================
   MODAL
   ============================================================ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
}

.modal.active {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: var(--bg-1);
  border: 1px solid var(--line-hi);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  color: var(--ink-hi);
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink-lo);
  cursor: pointer;
  transition: all var(--transition);
}

.modal-close:hover {
  background: var(--bg-3);
  color: var(--ink-hi);
}

/* ============================================================
   NOTIFICATION DOT
   ============================================================ */

.notification-dot {
  width: 8px;
  height: 8px;
  background: var(--err);
  border-radius: 50%;
  display: inline-block;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ============================================================
   TABS
   ============================================================ */

.tab-nav {
  display: flex;
  align-items: center;
  gap: 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
}

.tab-item {
  padding: 12px 20px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink-lo);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
}

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

.tab-item.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ============================================================
   PILLS (Level indicators)
   ============================================================ */

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 100px;
  letter-spacing: 0.03em;
}

.pill-l1 {
  background: var(--flow-lo);
  color: var(--flow);
}

.pill-l2 {
  background: rgba(139,201,154,0.12);
  color: var(--ok);
}

.pill-l3 {
  background: rgba(142,197,252,0.12);
  color: #8EC5FC;
}

.pill-l4 {
  background: rgba(188,160,220,0.12);
  color: #BCA0DC;
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */

.toast-container {
  position: fixed;
  top: 72px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  background: var(--bg-3);
  border: 1px solid var(--line-hi);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  color: var(--ink);
  min-width: 280px;
  animation: slideIn 0.3s ease;
}

.toast-success {
  border-left: 3px solid var(--ok);
}

.toast-error {
  border-left: 3px solid var(--err);
}

.toast-info {
  border-left: 3px solid var(--flow);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ============================================================
   EMPTY STATE
   ============================================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 24px;
  text-align: center;
}

.empty-state .empty-icon {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  opacity: 0.3;
}

.empty-state .empty-title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  color: var(--ink-lo);
  margin-bottom: 8px;
}

.empty-state .empty-desc {
  font-size: 0.875rem;
  color: var(--ink-mute);
  max-width: 320px;
}

/* ============================================================
   CHART CONTAINER
   ============================================================ */

.chart-container {
  width: 100%;
  height: 320px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
}

.chart-container.chart-sm {
  height: 220px;
}

.chart-container.chart-lg {
  height: 440px;
}

/* ============================================================
   PAGE HEADER
   ============================================================ */

.page-header {
  margin-bottom: 32px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.page-header .page-title {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  color: var(--ink-hi);
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.page-header .page-subtitle {
  font-size: 0.875rem;
  color: var(--ink-lo);
}

/* ============================================================
   AVATAR
   ============================================================ */

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-3);
  border: 1px solid var(--line-hi);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ink-lo);
  overflow: hidden;
}

.avatar-sm {
  width: 24px;
  height: 24px;
  font-size: 0.65rem;
}

.avatar-lg {
  width: 48px;
  height: 48px;
  font-size: 1rem;
}

/* ============================================================
   LOADING SPINNER
   ============================================================ */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.loading::after {
  content: '';
  width: 24px;
  height: 24px;
  border: 2px solid var(--line-hi);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ============================================================
   ANIMATIONS
   ============================================================ */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-fadeIn {
  animation: fadeIn 0.4s ease;
}

.animate-slideUp {
  animation: slideUp 0.4s ease;
}

/* ============================================================
   RESPONSIVE: Tablet (max 960px)
   ============================================================ */

@media (max-width: 960px) {
  .app-container {
    padding: 0 20px;
  }

  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .chart-container {
    min-height: 250px;
  }

  .data-table {
    font-size: 0.8rem;
  }

  .modal-content {
    width: 95%;
    max-width: none;
    margin: 20px;
  }

  .page-header .page-title {
    font-size: 1.4rem;
  }

  .sidebar {
    transform: translateX(-260px);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .mast {
    padding: 0 16px;
  }

  .mast-nav {
    gap: 16px;
  }
}

/* ============================================================
   RESPONSIVE: Phone (max 640px)
   ============================================================ */

@media (max-width: 640px) {
  .app-container {
    padding: 0 12px;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .stat-card {
    padding: 16px;
  }

  .card {
    padding: 16px;
  }

  .chart-container {
    min-height: 200px;
  }

  .page-header {
    padding: 16px 0;
  }

  .page-header .page-title {
    font-size: 1.1rem;
  }

  .tab-nav {
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .tab-item {
    padding: 8px 14px;
    font-size: 0.8rem;
  }

  .btn {
    padding: 8px 16px;
    font-size: 0.8rem;
  }

  .data-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .modal-card {
    width: 100%;
    height: 100%;
    max-width: none;
    border-radius: 0;
    margin: 0;
  }

  .modal-content {
    width: 100%;
    height: 100%;
    max-width: none;
    border-radius: 0;
    margin: 0;
  }

  .form-group {
    margin-bottom: 14px;
  }

  .main-content {
    padding: 20px 12px 48px;
  }

  .data-table th,
  .data-table td {
    padding: 10px 12px;
  }

  /* Masthead: stack on small screens */
  .mast {
    height: auto;
    flex-wrap: wrap;
    padding: 12px 12px;
    gap: 8px;
  }

  .mast-logo {
    font-size: 1.05rem;
  }

  .mast-nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    gap: 14px;
    padding-bottom: 4px;
    border-top: 1px solid var(--line);
    padding-top: 8px;
  }

  .mast-nav a {
    font-size: 0.8rem;
  }

  .toast-container {
    right: 12px;
    left: 12px;
  }

  .toast {
    min-width: auto;
  }
}

/* ============================================================
   UTILITY CLASSES
   ============================================================ */

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-accent { color: var(--accent); }
.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }
.text-err { color: var(--err); }
.text-muted { color: var(--ink-lo); }
.text-mono { font-family: var(--font-mono); }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.hidden { display: none; }
