:root {
  --primary: #1E5A8E;
  --primary-light: #2A7AB5;
  --primary-dark: #164A73;
  --secondary: #34A853;
  --surface: #FFFFFF;
  --background: #F8F9FA;
  --text-primary: #1A1A1A;
  --text-secondary: #666666;
  --border: #E0E0E0;
  --error: #D93025;
  --success: #34A853;
  --table-header: #1E5A8E;
  --card-bg: #FFFFFF;
  --input-bg: #FFFFFF;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--background);
  color: var(--text-primary);
  min-height: 100vh;
}

#root {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--primary);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}

.sidebar-header h1 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}

.sidebar-header p {
  font-size: 12px;
  opacity: 0.7;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: rgba(255,255,255,0.1);
  color: white;
}

.nav-item.active {
  background: rgba(255,255,255,0.2);
  color: white;
  font-weight: 600;
}

.nav-item .material-icons-outlined {
  font-size: 22px;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.15);
}

.sidebar-footer button {
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(255,255,255,0.7);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 8px 0;
  width: 100%;
}

.sidebar-footer button:hover {
  color: white;
}

.main-content {
  flex: 1;
  margin-left: 260px;
  padding: 24px 32px;
  min-height: 100vh;
}

.page-header {
  margin-bottom: 24px;
}

.page-header h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
}

.page-header p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

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

.card-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  padding: 20px;
}

.auth-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 420px;
}

.auth-card h1 {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
  color: var(--primary);
}

.auth-card .subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 32px;
}

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

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  transition: border-color 0.2s;
  background: var(--input-bg);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-light);
}

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

.btn-secondary {
  background: var(--background);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: #2d9249;
}

.btn-danger {
  background: var(--error);
  color: white;
}

.btn-danger:hover {
  background: #c42b1f;
}

.btn-full {
  width: 100%;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 13px;
}

.btn-icon {
  padding: 8px;
  border-radius: 8px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--background);
  color: var(--primary);
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  padding: 0;
  text-decoration: underline;
}

.link-btn:hover {
  color: var(--primary-light);
}

.message {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
}

.message-error {
  background: #FEE2E2;
  color: var(--error);
  border: 1px solid #FECACA;
}

.message-success {
  background: #D1FAE5;
  color: #065F46;
  border: 1px solid #A7F3D0;
}

.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

table th {
  background: var(--table-header);
  color: white;
  padding: 10px 12px;
  text-align: center;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

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

table tr:hover {
  background: #F0F7FF;
}

table tr.sunday {
  background: #FFF3F3;
}

table tr.sunday:hover {
  background: #FFE8E8;
}

table tr.total-row {
  background: var(--primary);
  color: white;
  font-weight: 700;
}

table tr.total-row:hover {
  background: var(--primary);
}

table td input {
  width: 90px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-align: right;
  font-size: 14px;
  font-family: inherit;
}

table td input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(30,90,142,0.15);
}

table td input:disabled {
  background: #F5F5F5;
  color: var(--text-secondary);
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.month-nav h3 {
  font-size: 18px;
  font-weight: 600;
  min-width: 200px;
  text-align: center;
  text-transform: capitalize;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  text-align: center;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar-right {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-success {
  background: #D1FAE5;
  color: #065F46;
}

.badge-warning {
  background: #FEF3C7;
  color: #92400E;
}

.badge-error {
  background: #FEE2E2;
  color: #991B1B;
}

.badge-info {
  background: #DBEAFE;
  color: #1E40AF;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 32px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  color: var(--text-secondary);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state .material-icons-outlined {
  font-size: 48px;
  color: var(--border);
  margin-bottom: 12px;
}

.key-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.key-card .key-value {
  font-family: 'Courier New', monospace;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 1px;
}

.key-card .key-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.key-actions {
  display: flex;
  gap: 4px;
}

.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}

.tab {
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
  font-family: inherit;
}

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

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

.profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.report-month {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.report-month:hover {
  border-color: var(--primary);
  background: #F0F7FF;
}

.report-month .month-name {
  font-weight: 600;
  text-transform: capitalize;
}

.report-month .month-total {
  font-weight: 700;
  color: var(--primary);
}

.subscription-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--background);
  padding: 20px;
}

.subscription-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 480px;
  text-align: center;
}

.subscription-card h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}

.subscription-card p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.key-input-group {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.key-input-group input {
  flex: 1;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: 'Courier New', monospace;
  text-align: center;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.key-input-group input:focus {
  outline: none;
  border-color: var(--primary);
}

.footer-text {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 20px;
}

.hamburger {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
}

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

/* ── Tablet (≤1024px) ──────────────────────────────────────────── */
@media (max-width: 1024px) {
  .sidebar {
    width: 220px;
  }

  .main-content {
    margin-left: 220px;
    padding: 20px 20px;
  }

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

  .stat-card .stat-value {
    font-size: 22px;
  }
}

/* ── Mobile (≤768px) ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    width: 280px;
    transform: translateX(-100%);
  }

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

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

  .hamburger {
    display: flex;
  }

  .main-content {
    margin-left: 0;
    padding: 12px;
    padding-top: 60px;
  }

  .page-header {
    margin-bottom: 16px;
  }

  .page-header h2 {
    font-size: 18px;
  }

  .page-header p {
    font-size: 12px;
  }

  .card {
    padding: 14px;
    margin-bottom: 12px;
    border-radius: 10px;
  }

  /* Grids */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
  }

  .stat-card {
    padding: 14px 10px;
  }

  .stat-card .stat-value {
    font-size: 18px;
  }

  .stat-card .stat-label {
    font-size: 11px;
  }

  .profile-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  /* Month nav */
  .month-nav {
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
  }

  .month-nav h3 {
    font-size: 15px;
    min-width: 0;
    flex: 1;
    text-align: center;
  }

  /* Toolbar */
  .toolbar {
    flex-wrap: wrap;
    gap: 6px;
    align-items: flex-start;
  }

  .toolbar-right {
    margin-left: 0;
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
  }

  .toolbar-right .btn {
    flex: 1;
    min-width: 0;
    justify-content: center;
  }

  /* Tables */
  table {
    font-size: 11px;
  }

  table th {
    padding: 7px 3px;
    font-size: 10px;
    letter-spacing: 0;
  }

  table td {
    padding: 6px 3px;
  }

  table td input {
    width: 62px;
    font-size: 11px;
    padding: 4px 4px;
  }

  table td select {
    width: 82px;
    font-size: 10px;
    padding: 3px 2px;
  }

  /* Buttons */
  .btn {
    padding: 9px 12px;
    font-size: 13px;
  }

  .btn-sm {
    padding: 6px 10px;
    font-size: 11px;
  }

  /* Auth */
  .auth-card {
    padding: 24px 16px;
    margin: 12px;
    max-width: calc(100vw - 24px);
  }

  /* Modals */
  .modal {
    padding: 20px 16px;
    max-width: calc(100vw - 20px);
    max-height: 95vh;
  }

  .modal-actions {
    flex-direction: column-reverse;
    gap: 8px;
  }

  .modal-actions .btn {
    width: 100%;
  }

  .privacy-modal {
    max-width: calc(100vw - 20px);
    max-height: 95vh;
  }

  /* Misc */
  .backup-actions {
    flex-direction: column;
  }

  .backup-freq-buttons {
    flex-wrap: wrap;
  }

  .register-table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .key-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .key-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .tabs {
    overflow-x: auto;
  }

  .tab {
    padding: 10px 14px;
    white-space: nowrap;
  }
}

/* ── Small phones (≤480px) ─────────────────────────────────────── */
@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stat-card .stat-value {
    font-size: 20px;
  }

  .month-nav h3 {
    font-size: 14px;
  }

  table {
    font-size: 10px;
  }

  table th {
    font-size: 9px;
    padding: 6px 2px;
  }

  table td {
    padding: 5px 2px;
  }

  table td input {
    width: 54px;
    font-size: 10px;
  }

  table td select {
    width: 68px;
    font-size: 9px;
  }

  .page-header h2 {
    font-size: 16px;
  }

  .card {
    padding: 12px;
  }
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.checkbox-group label {
  font-size: 14px;
  color: var(--text-primary);
}

.password-wrapper {
  position: relative;
}

.password-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
}

.select-wrapper 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 fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.locked-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: #FEF3C7;
  color: #92400E;
}

.print-hidden {
  display: block;
}

@media print {
  .sidebar, .hamburger, .sidebar-overlay, .toolbar, .month-nav button, .print-hidden {
    display: none !important;
  }

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

  .card {
    box-shadow: none;
    border: 1px solid #ddd;
  }
}

.privacy-modal {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.privacy-modal-header {
  padding: 20px 24px 12px;
  border-bottom: 1px solid var(--border);
}

.privacy-modal-header h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

.privacy-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.privacy-tab {
  flex: 1;
  padding: 12px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.privacy-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.privacy-scroll-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  min-height: 250px;
  max-height: 45vh;
  line-height: 1.6;
}

.privacy-scroll-content h3 {
  font-size: 15px;
  font-weight: 700;
  margin: 16px 0 8px;
}

.privacy-scroll-content h3:first-child {
  margin-top: 0;
}

.privacy-scroll-content p {
  font-size: 13px;
  color: #555;
  margin: 0 0 10px;
  text-align: justify;
}

.privacy-scroll-hint {
  text-align: center;
  font-size: 12px;
  font-style: italic;
  color: #888;
  padding: 8px;
  border-top: 1px solid var(--border);
}

.privacy-accept-bar {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  background: #fafafa;
}

.privacy-accept-bar .checkbox-group {
  margin-bottom: 12px;
}

.privacy-accept-bar .checkbox-group input:disabled + label {
  opacity: 0.4;
}

.privacy-open-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

.privacy-open-btn:hover {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.05);
}

.privacy-open-btn.privacy-accepted {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.08);
  color: var(--primary);
}

.backup-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.backup-actions .btn {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 140px;
  justify-content: center;
}

.backup-freq-buttons {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

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

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-weight: 500;
  transition: all 0.2s;
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-secondary {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-weight: 500;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: var(--border);
}
