/* ========== RESET & BASE ========== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #F5F0EB;
  --bg-secondary: #FFFFFF;
  --bg-card: #FAF8F5;
  --text-primary: #3D3D3D;
  --text-secondary: #6B6B6B;
  --text-muted: #999999;
  --border-color: #E8E4DF;
  --accent-gold: #BB9D4B;
  --accent-red: #DA251C;
  --accent-blue: #7BA3C4;
  --accent-green: #C3D8CB;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --radius: 8px;
  --radius-lg: 12px;
  --nav-width: 220px;
  --header-height: 60px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ========== LOGIN ========== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #F5F0EB 0%, #E8E4DF 100%);
}

.login-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  padding: 48px 40px;
  width: 380px;
  max-width: 90vw;
}

.login-card h1 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 8px;
}

.login-card p {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 32px;
}

.login-card label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.login-card input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
  background: var(--bg-card);
}

.login-card input:focus {
  border-color: var(--accent-gold);
}

.login-btn {
  width: 100%;
  padding: 11px;
  background: var(--accent-gold);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 20px;
  transition: opacity 0.2s;
}

.login-btn:hover { opacity: 0.9; }

.login-error {
  color: var(--accent-red);
  font-size: 13px;
  text-align: center;
  margin-top: 12px;
  display: none;
}

/* ========== LAYOUT ========== */
.app-container {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--nav-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  overflow-y: auto;
  padding-top: 16px;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 0 16px 16px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 8px;
  position: relative;
}

.sidebar-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.sidebar-header .subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.sidebar-close {
  display: none;
  position: absolute;
  top: 0;
  right: 12px;
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.3);
  z-index: 99;
}

.sidebar-overlay.show {
  display: block;
}

.nav-list {
  list-style: none;
  padding: 4px 0;
}

.nav-item {
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all 0.15s;
  border-left: 3px solid transparent;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-item:hover {
  background: rgba(187, 157, 75, 0.06);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(187, 157, 75, 0.10);
  color: var(--text-primary);
  border-left-color: var(--accent-gold);
  font-weight: 500;
}

.nav-item .nav-indicator {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent-gold);
  flex-shrink: 0;
  opacity: 0;
}

.nav-item.active .nav-indicator {
  opacity: 1;
}

.nav-section-label {
  padding: 12px 16px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 500;
}

.main-content {
  margin-left: var(--nav-width);
  flex: 1;
  padding: 24px 32px 40px;
  min-height: 100vh;
}

/* ========== HEADER ========== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.page-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.page-header h1 {
  font-size: 20px;
  font-weight: 600;
}

.page-header .user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}

.logout-btn {
  padding: 6px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.logout-btn:hover {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

/* ========== CARDS ========== */
.card {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 20px;
}

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

.card-header h3 {
  font-size: 15px;
  font-weight: 500;
}

/* ========== CHARTS ========== */
.chart-container {
  width: 100%;
  min-height: 400px;
  transition: height 0.3s;
}

/* ========== CONTROLS ========== */
.controls-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.controls-bar select, .controls-bar button, .controls-bar input {
  padding: 8px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}

.controls-bar select:focus, .controls-bar input:focus {
  border-color: var(--accent-gold);
}

.controls-bar button {
  background: var(--bg-card);
  cursor: pointer;
  transition: all 0.15s;
}

.controls-bar button:hover {
  border-color: var(--accent-gold);
  background: rgba(187, 157, 75, 0.06);
}

.controls-bar button.active {
  background: var(--accent-gold);
  color: #fff;
  border-color: var(--accent-gold);
}

.compare-info {
  padding: 12px 16px;
  background: rgba(187, 157, 75, 0.06);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  border-left: 3px solid var(--accent-gold);
}

.compare-info .highlight-up {
  color: var(--accent-red);
  font-weight: 500;
}

.compare-info .highlight-down {
  color: var(--accent-green);
  font-weight: 500;
}

/* ========== NAVIGATION GRID ========== */
.page-nav {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
}

.page-nav-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.page-nav-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.page-nav-btn {
  padding: 6px 14px;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  background: var(--bg-card);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.page-nav-btn:hover {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

.page-nav-btn.current {
  background: var(--accent-gold);
  color: #fff;
  border-color: var(--accent-gold);
}

/* ========== DASHBOARD ========== */
.dashboard-summary {
  margin-bottom: 24px;
}

.summary-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 20px;
}

.summary-header h3 {
  font-size: 17px;
  font-weight: 600;
}

.summary-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.kpi-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  position: relative;
  transition: transform 0.15s, box-shadow 0.15s;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.10);
}

.kpi-icon {
  font-size: 24px;
  margin-bottom: 8px;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.kpi-unit {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.kpi-yoy {
  font-size: 12px;
  color: var(--text-secondary);
  padding-top: 8px;
  border-top: 1px solid var(--border-color);
}

.dashboard-section {
  margin-bottom: 24px;
}

.dashboard-section h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.dashboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.dashboard-table th {
  background: var(--bg-card);
  padding: 10px 12px;
  text-align: center;
  border: 1px solid var(--border-color);
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 12px;
}

.dashboard-table td {
  padding: 8px 12px;
  text-align: center;
  border: 1px solid var(--border-color);
}

.dashboard-table tr:hover td {
  background: rgba(187, 157, 75, 0.03);
}

/* ========== DATA EDIT TABLE ========== */
.data-edit-table-wrap {
  overflow-x: auto;
}

.data-edit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  min-width: 800px;
}

.data-edit-table th {
  background: var(--bg-card);
  padding: 8px 6px;
  text-align: center;
  border: 1px solid var(--border-color);
  font-weight: 500;
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.data-edit-table td {
  padding: 4px 2px;
  text-align: center;
  border: 1px solid var(--border-color);
}

.data-edit-table td input {
  width: 70px;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  text-align: center;
  font-size: 12px;
  outline: none;
  background: transparent;
  transition: all 0.15s;
}

.data-edit-table td input:hover {
  border-color: var(--border-color);
  background: rgba(187, 157, 75, 0.04);
}

.data-edit-table td input:focus {
  border-color: var(--accent-gold);
  background: rgba(187, 157, 75, 0.06);
}

.data-edit-table tr:hover td {
  background: rgba(187, 157, 75, 0.03);
}

.data-edit-table .row-year {
  font-weight: 500;
  color: var(--text-primary);
  min-width: 50px;
}

.data-edit-table .row-month {
  min-width: 40px;
}

.data-edit-table .total-row td {
  background: rgba(187, 157, 75, 0.06);
  font-weight: 500;
  border-top: 2px solid var(--accent-gold);
}

.data-edit-table .total-val {
  color: var(--accent-gold);
}

/* ========== BUTTONS ========== */
.btn-primary {
  padding: 8px 20px;
  background: var(--accent-gold);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-primary:hover { opacity: 0.9; }

.btn-danger {
  padding: 8px 20px;
  background: transparent;
  color: var(--accent-red);
  border: 1px solid var(--accent-red);
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-danger:hover {
  background: rgba(218, 37, 28, 0.06);
}

.btn-secondary {
  padding: 8px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-secondary:hover {
  border-color: var(--accent-gold);
}

/* ========== TOAST ========== */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 1000;
  opacity: 0;
  transform: translateY(-10px);
  transition: all 0.3s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  max-width: 360px;
}

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

.toast.success {
  background: #E8F0E4;
  color: #3D6B3D;
  border: 1px solid #C3D8CB;
}

.toast.error {
  background: #F8E8E8;
  color: #8B3A3A;
  border: 1px solid #E8C0C0;
}

.toast.info {
  background: #E4ECF2;
  color: #3A5A7A;
  border: 1px solid #C0D0E0;
}

/* ========== PAGE STATE ========== */
.page-view { display: none; }
.page-view.active { display: block; }

/* ========== EMPTY & ERROR STATES ========== */
.empty-state, .error-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

.error-state .error-icon {
  display: block;
  font-size: 36px;
  margin-bottom: 12px;
}

.error-state p {
  font-size: 14px;
  color: var(--accent-red);
}

/* ========== MODAL ========== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.35);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  width: 420px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}

.modal h3 {
  font-size: 17px;
  margin-bottom: 12px;
}

.modal p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.file-input-wrap {
  position: relative;
  margin-bottom: 16px;
}

.file-input-wrap input[type="file"] {
  width: 100%;
  padding: 10px;
  border: 1px dashed var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-card);
  cursor: pointer;
  font-size: 13px;
}

.file-input-wrap input[type="file"]:hover {
  border-color: var(--accent-gold);
}

/* ========== RESPONSIVE ========== */
@media (max-width: 900px) {
  .sidebar {
    width: 56px;
    overflow: hidden;
  }
  .sidebar .nav-item span,
  .sidebar .nav-section-label,
  .sidebar-header .subtitle,
  .sidebar-header h2 {
    display: none;
  }
  .sidebar-header {
    padding: 8px;
    text-align: center;
  }
  .sidebar-header h2::after {
    content: 'ED';
    display: block;
    font-size: 18px;
  }
  .sidebar-close {
    display: none;
  }
  .hamburger-btn {
    display: inline-block;
  }
  .main-content {
    margin-left: 56px;
    padding: 16px;
  }
  .controls-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .controls-bar select, .controls-bar button {
    width: 100%;
  }
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .kpi-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
  }
}

@media (max-width: 600px) {
  .login-card { padding: 32px 24px; }
  .modal { padding: 20px; }
  .page-nav-grid { gap: 4px; }
  .page-nav-btn { font-size: 11px; padding: 4px 10px; }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .kpi-card { padding: 14px; }
  .kpi-value { font-size: 22px; }
}

/* Mobile sidebar (full overlay) */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: 260px;
  }
  .sidebar.collapsed {
    transform: translateX(0);
  }
  .sidebar .nav-item span,
  .sidebar .nav-section-label,
  .sidebar-header .subtitle,
  .sidebar-header h2 {
    display: block;
  }
  .sidebar-header h2::after {
    content: none;
    display: none;
  }
  .sidebar-close {
    display: block;
  }
  .hamburger-btn {
    display: inline-block;
  }
  .main-content {
    margin-left: 0;
    padding: 12px;
  }
}
