/* ============================================================
   HowLong — Main Stylesheet
   Supports light / dark theme via [data-theme] on <html>
   ============================================================ */

/* ---------- CSS Custom Properties ---------- */
:root {
  /* Light theme */
  --color-bg:           #f8fafc;
  --color-surface:      #ffffff;
  --color-surface-alt:  #f1f5f9;
  --color-border:       #e2e8f0;
  --color-border-light: #f1f5f9;

  --color-text:         #0f172a;
  --color-text-muted:   #64748b;
  --color-text-subtle:  #94a3b8;

  /* Sidebar */
  --sidebar-bg:         #1e293b;
  --sidebar-text:       #cbd5e1;
  --sidebar-text-hover: #f8fafc;
  --sidebar-active-bg:  rgba(255,255,255,0.12);
  --sidebar-active-text:#ffffff;
  --sidebar-section-label: #475569;
  --sidebar-border:     rgba(255,255,255,0.07);
  --sidebar-width:      260px;

  /* Topbar */
  --topbar-bg:          #ffffff;
  --topbar-border:      #e2e8f0;
  --topbar-height:      60px;

  /* Brand colours */
  --color-primary:      #3b82f6;
  --color-primary-dark: #2563eb;
  --color-primary-light:#eff6ff;

  --color-success:      #22c55e;
  --color-success-bg:   #f0fdf4;
  --color-warning:      #f59e0b;
  --color-warning-bg:   #fffbeb;
  --color-danger:       #ef4444;
  --color-danger-bg:    #fef2f2;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:  0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg:  0 12px 32px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.06);

  /* Radii */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;

  /* Transitions */
  --transition: 0.18s ease;
}

[data-theme="dark"] {
  --color-bg:           #0f172a;
  --color-surface:      #1e293b;
  --color-surface-alt:  #162032;
  --color-border:       #334155;
  --color-border-light: #1e293b;

  --color-text:         #f1f5f9;
  --color-text-muted:   #94a3b8;
  --color-text-subtle:  #64748b;

  --sidebar-bg:         #0d1829;
  --sidebar-text:       #94a3b8;
  --sidebar-text-hover: #f1f5f9;
  --sidebar-active-bg:  rgba(255,255,255,0.08);
  --sidebar-section-label: #334155;
  --sidebar-border:     rgba(255,255,255,0.04);

  --topbar-bg:          #1e293b;
  --topbar-border:      #334155;

  --color-primary-light:#1e3a5f;
  --color-success-bg:   #052e16;
  --color-warning-bg:   #271a00;
  --color-danger-bg:    #2d0a0a;

  --shadow-sm:  0 1px 3px rgba(0,0,0,.3);
  --shadow-md:  0 4px 12px rgba(0,0,0,.4);
  --shadow-lg:  0 12px 32px rgba(0,0,0,.5);
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

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

/* ---------- App Layout (sidebar + content) ---------- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform var(--transition), width var(--transition);
  overflow: hidden;
}

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

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 22px;
  line-height: 1;
}

.logo-name-wrap {
  display: flex;
  flex-direction: column;
  line-height: 1;
  gap: 2px;
}

.logo-text {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.3px;
}

.logo-beta {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: #111;
  background: #fbbf24;
  border: none;
  border-radius: 3px;
  padding: 1px 5px;
  align-self: flex-start;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  overflow-y: auto;
  gap: 2px;
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-section-label);
  padding: 8px 8px 4px;
  display: block;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 14px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
}

.nav-item:hover {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-hover);
  text-decoration: none;
}

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}

.nav-item-danger:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.8;
}

.nav-item:hover .nav-icon,
.nav-item.active .nav-icon { opacity: 1; }

.nav-bottom {
  flex-shrink: 0;
  padding-top: 12px;
  border-top: 1px solid var(--sidebar-border);
}

.nav-version {
  font-size: 11px;
  color: var(--sidebar-text);
  opacity: 0.45;
  padding: 2px 12px 4px;
}

.nav-legal {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px 8px;
  font-size: 11px;
}

.nav-legal a {
  color: var(--sidebar-text);
  opacity: 0.5;
  text-decoration: none;
}

.nav-legal a:hover { opacity: 0.85; }

.nav-legal-sep {
  color: var(--sidebar-text);
  opacity: 0.3;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 4px;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), #7c3aed);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-details {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 11px;
  color: var(--sidebar-text);
}

/* ---------- Main Wrapper ---------- */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left var(--transition);
}

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-height);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
  transition: background var(--transition), border-color var(--transition);
}

.topbar-title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 6px;
  border-radius: var(--radius-sm);
  display: none;
  transition: background var(--transition), color var(--transition);
}

.sidebar-toggle:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

/* ---------- Theme Toggle ---------- */
.theme-toggle {
  background: none;
  border: 1px solid var(--color-border);
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 7px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  width: 36px;
  height: 36px;
}

.theme-toggle:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
  border-color: var(--color-primary);
}

.icon-moon { display: none; }
[data-theme="dark"] .icon-sun  { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ---------- Main Content ---------- */
.content {
  flex: 1;
  padding: 28px 28px 40px;
  max-width: 1200px;
  width: 100%;
}

/* ---------- Page Header ---------- */
.page-header {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 28px;
}

.page-heading {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
  flex: 1 1 auto;
}

.page-subheading {
  width: 100%;
  font-size: 14px;
  color: var(--color-text-muted);
  margin-top: -4px;
}

.page-header .btn { margin-left: auto; align-self: center; }

/* ---------- Cards ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), border-color var(--transition);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body {
  padding: 20px;
}

.card-body.p-0 { padding: 0; }

.card-footer {
  padding: 14px 20px;
  background: var(--color-surface-alt);
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ---------- Content Grids ---------- */
.content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 20px;
}

.content-grid-narrow {
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

/* ---------- Stats Grid ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}

.stat-card:hover { box-shadow: var(--shadow-md); }

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon-blue   { background: #eff6ff; color: #3b82f6; }
.stat-icon-green  { background: #f0fdf4; color: #22c55e; }
.stat-icon-amber  { background: #fffbeb; color: #f59e0b; }
.stat-icon-purple { background: #faf5ff; color: #a855f7; }

[data-theme="dark"] .stat-icon-blue   { background: #1e3a5f; }
[data-theme="dark"] .stat-icon-green  { background: #052e16; }
[data-theme="dark"] .stat-icon-amber  { background: #271a00; }
[data-theme="dark"] .stat-icon-purple { background: #2e1065; }

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--color-text);
}

.stat-label {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* ---------- Detail List ---------- */
.detail-list { display: flex; flex-direction: column; gap: 0; }

.detail-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border-light);
  font-size: 14px;
}

.detail-row:last-child { border-bottom: none; }

.detail-row dt {
  min-width: 130px;
  color: var(--color-text-muted);
  font-weight: 500;
  flex-shrink: 0;
}

.detail-row dd { color: var(--color-text); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  line-height: 1.6;
  white-space: nowrap;
}

.badge-blue   { background: #eff6ff; color: #2563eb; }
.badge-green  { background: #f0fdf4; color: #16a34a; }
.badge-red    { background: #fef2f2; color: #dc2626; }
.badge-gray   { background: var(--color-surface-alt); color: var(--color-text-muted); }
.badge-amber  { background: #fffbeb; color: #d97706; }
.badge-xs     { font-size: 10px; padding: 1px 6px; }

[data-theme="dark"] .badge-blue  { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .badge-green { background: #052e16; color: #86efac; }
[data-theme="dark"] .badge-red   { background: #2d0a0a; color: #fca5a5; }
[data-theme="dark"] .badge-amber { background: #271a00; color: #fcd34d; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), box-shadow var(--transition),
              opacity var(--transition);
  white-space: nowrap;
  user-select: none;
}

.btn:hover { text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

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

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover {
  background: var(--color-surface-alt);
}

.btn-success {
  background: var(--color-success);
  color: #fff;
  border-color: var(--color-success);
}
.btn-success:hover { opacity: 0.9; }

.btn-warning {
  background: var(--color-warning);
  color: #fff;
  border-color: var(--color-warning);
}
.btn-warning:hover { opacity: 0.9; }

.btn-danger {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}
.btn-danger:hover { opacity: 0.9; }

.btn-sm {
  padding: 5px 12px;
  font-size: 13px;
}

.btn-full { width: 100%; justify-content: center; }

/* ---------- Forms ---------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 18px;
}

.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
}

.form-input {
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  width: 100%;
  appearance: none;
}

.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.18);
}

.form-input::placeholder { color: var(--color-text-subtle); }

.form-input-code {
  font-size: 24px;
  letter-spacing: 0.3em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.form-check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.form-checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--color-primary);
}

.form-check-label {
  font-size: 14px;
  color: var(--color-text);
  cursor: pointer;
}

.form-error {
  font-size: 12px;
  color: var(--color-danger);
}

.form-hint {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 4px;
}

/* Password input wrapper */
.input-password-wrapper {
  position: relative;
}

.input-password-wrapper .form-input {
  padding-right: 44px;
}

.password-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-subtle);
  padding: 4px;
  display: flex;
  align-items: center;
  transition: color var(--transition);
}

.password-toggle:hover,
.password-toggle.active { color: var(--color-primary); }

/* ---------- Auth Layout ---------- */
.auth-layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  background: var(--color-bg);
  transition: background var(--transition);
  position: relative;
}

.auth-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 36px 36px 32px;
  width: 100%;
  max-width: 420px;
  transition: background var(--transition), border-color var(--transition);
}

.auth-card-wide { max-width: 500px; }

.auth-card-header {
  text-align: center;
  margin-bottom: 28px;
}

.auth-logo { margin-bottom: 12px; }

.logo-icon-large {
  font-size: 40px;
  line-height: 1;
  display: block;
}

.auth-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 6px;
}

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

.auth-form { display: flex; flex-direction: column; }

.auth-footer-links {
  text-align: center;
  margin-top: 16px;
  font-size: 13px;
}

.link-muted { color: var(--color-text-muted); }
.link-muted:hover { color: var(--color-text); }

.theme-toggle-fixed {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
}

/* ---------- 2FA Setup ---------- */
.setup-2fa-steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.step {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.step-number {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.step-content h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 2px;
}

.step-content p {
  font-size: 13px;
  color: var(--color-text-muted);
}

.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  gap: 12px;
}

.qr-image {
  width: 180px;
  height: 180px;
  border-radius: var(--radius-sm);
  image-rendering: pixelated;
}

.secret-key {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

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

.secret-code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 0.08em;
  color: var(--color-primary);
  word-break: break-all;
}

.btn-copy {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  cursor: pointer;
  padding: 4px 6px;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  transition: all var(--transition);
}

.btn-copy:hover { color: var(--color-primary); border-color: var(--color-primary); }
.btn-copy.copied { color: var(--color-success); border-color: var(--color-success); }

/* ---------- Flash Messages ---------- */
.flash-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.flash-auth {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  width: 90%;
  max-width: 440px;
}

.alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  border-width: 1px;
  border-style: solid;
  animation: slideDown 0.2s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.alert-success { background: var(--color-success-bg); border-color: #86efac; color: #166534; }
.alert-error   { background: var(--color-danger-bg);  border-color: #fca5a5; color: #991b1b; }
.alert-info    { background: var(--color-primary-light); border-color: #93c5fd; color: #1e40af; }
.alert-warning { background: var(--color-warning-bg); border-color: #fcd34d; color: #92400e; }

[data-theme="dark"] .alert-success { color: #86efac; }
[data-theme="dark"] .alert-error   { color: #fca5a5; }
[data-theme="dark"] .alert-info    { color: #93c5fd; }
[data-theme="dark"] .alert-warning { color: #fcd34d; }

.alert-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  opacity: 0.6;
  padding: 0 2px;
  color: inherit;
  flex-shrink: 0;
}

.alert-close:hover { opacity: 1; }

/* ---------- Table ---------- */
.table-wrapper { overflow-x: auto; }

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

.table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface-alt);
  white-space: nowrap;
}

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

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

.table tbody tr:hover td { background: var(--color-surface-alt); }

.row-muted td { opacity: 0.55; }

.table-empty {
  text-align: center;
  color: var(--color-text-muted);
  padding: 40px !important;
}

.user-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar-sm {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), #7c3aed);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-cell-name { font-weight: 500; }

.action-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 460px;
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(-10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--color-border);
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0 4px;
  line-height: 1;
}

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

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ---------- Security Status Banners ---------- */
.security-items { display: flex; flex-direction: column; gap: 14px; }

.security-item {
  display: flex;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  align-items: flex-start;
}

.security-ok   { background: var(--color-success-bg); border-color: #86efac; }
.security-warn { background: var(--color-warning-bg); border-color: #fcd34d; }

[data-theme="dark"] .security-ok   { border-color: #166534; }
[data-theme="dark"] .security-warn { border-color: #92400e; }

.security-item-icon {
  flex-shrink: 0;
  margin-top: 2px;
}

.security-ok   .security-item-icon { color: var(--color-success); }
.security-warn .security-item-icon { color: var(--color-warning); }

.security-item-text { display: flex; flex-direction: column; gap: 2px; }
.security-item-text strong { font-size: 14px; font-weight: 600; color: var(--color-text); }
.security-item-text span   { font-size: 13px; color: var(--color-text-muted); }

.status-banner {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border-width: 1px;
  border-style: solid;
  align-items: flex-start;
}

.status-banner-green {
  background: var(--color-success-bg);
  border-color: #86efac;
  color: #166534;
}

.status-banner-amber {
  background: var(--color-warning-bg);
  border-color: #fcd34d;
  color: #92400e;
}

[data-theme="dark"] .status-banner-green { color: #86efac; }
[data-theme="dark"] .status-banner-amber { color: #fcd34d; }

.status-banner p {
  font-size: 13px;
  margin-top: 3px;
  opacity: 0.85;
}

/* ---------- Utilities ---------- */
.text-muted  { color: var(--color-text-muted) !important; }
.text-sm     { font-size: 13px !important; }
.mt-4        { margin-top: 16px; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }

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

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

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

  .sidebar-toggle { display: flex; }

  .content { padding: 20px 16px 32px; }

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

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

  .auth-card { padding: 28px 20px 24px; }

  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header .btn { margin-left: 0; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .table th, .table td { padding: 10px 12px; }
}


/* ============================================================
   Counter Dashboard — Additional Styles
   ============================================================ */

/* ---------- Animations ---------- */
@keyframes pulse-value {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.06); }
  100% { transform: scale(1); }
}

@keyframes count-up {
  0%   { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ---------- Counter Grid ---------- */
.counter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

/* ---------- Counter Tile ---------- */
.counter-tile {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-primary);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  cursor: grab;
  transition: box-shadow var(--transition), transform var(--transition), opacity var(--transition);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.counter-tile:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.counter-tile:active {
  cursor: grabbing;
}

.counter-tile.tile-small {
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
}
.counter-tile.tile-small .counter-tile-value {
  font-size: 1.25rem;
}

.counter-tile.tile-large {
  grid-column: span 2;
  padding: 1.75rem 2rem;
}
.counter-tile.tile-large .counter-tile-value {
  font-size: 2.5rem;
}

.counter-tile.inactive {
  opacity: 0.5;
}

.counter-tile.is-dragging {
  opacity: 0.8;
  transform: scale(1.02);
  box-shadow: var(--shadow-lg);
  cursor: grabbing;
}

.counter-tile.favorite {
  border-left-color: #f59e0b;
}

/* Type-colored left borders */
.counter-tile.type-salary    { border-left-color: #3b82f6; }
.counter-tile.type-smoke     { border-left-color: #22c55e; }
.counter-tile.type-alcohol   { border-left-color: #14b8a6; }
.counter-tile.type-holiday   { border-left-color: #f97316; }
.counter-tile.type-life      { border-left-color: #a855f7; }
.counter-tile.type-debt      { border-left-color: #ef4444; }
.counter-tile.type-wealth    { border-left-color: #10b981; }
.counter-tile.type-goal      { border-left-color: #6366f1; }
.counter-tile.type-event     { border-left-color: #ec4899; }
.counter-tile.type-retirement{ border-left-color: #f59e0b; }
.counter-tile.type-project   { border-left-color: #06b6d4; }
.counter-tile.type-abstinence{ border-left-color: #8b5cf6; }
.counter-tile.type-money-goal{ border-left-color: #84cc16; }

/* ---------- Counter Tile Parts ---------- */
.counter-tile-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.counter-tile-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--color-text);
  line-height: 1.3;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.counter-tile-value {
  font-size: 1.8rem;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace;
  color: var(--color-primary);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.counter-tile-value.value-updated {
  animation: pulse-value 0.45s ease-out;
}

.counter-tile-subvalue {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}

.counter-tile-actions {
  display: flex;
  gap: 0.375rem;
  align-items: center;
  margin-top: auto;
  padding-top: 0.5rem;
  flex-wrap: wrap;
}
.counter-tile-actions .btn {
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  line-height: 1.4;
}

/* ---------- Type Badges ---------- */
.type-badge {
  display: inline-block;
  padding: 0.15em 0.55em;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
  line-height: 1.6;
}

.type-badge.type-salary {
  background: #dbeafe;
  color: #1d4ed8;
}
.type-badge.type-smoke {
  background: #dcfce7;
  color: #15803d;
}
.type-badge.type-alcohol {
  background: #ccfbf1;
  color: #0f766e;
}
.type-badge.type-holiday {
  background: #ffedd5;
  color: #c2410c;
}
.type-badge.type-life {
  background: #f3e8ff;
  color: #7e22ce;
}
.type-badge.type-debt {
  background: #fee2e2;
  color: #b91c1c;
}
.type-badge.type-wealth {
  background: #d1fae5;
  color: #065f46;
}
.type-badge.type-goal {
  background: #e0e7ff;
  color: #3730a3;
}
.type-badge.type-event {
  background: #fce7f3;
  color: #9d174d;
}
.type-badge.type-retirement {
  background: #fef3c7;
  color: #92400e;
}
.type-badge.type-project {
  background: #cffafe;
  color: #155e75;
}
.type-badge.type-abstinence {
  background: #ede9fe;
  color: #5b21b6;
}
.type-badge.type-money-goal {
  background: #ecfccb;
  color: #3f6212;
}

[data-theme="dark"] .type-badge.type-salary     { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .type-badge.type-smoke      { background: #14382b; color: #86efac; }
[data-theme="dark"] .type-badge.type-alcohol    { background: #134e4a; color: #5eead4; }
[data-theme="dark"] .type-badge.type-holiday    { background: #431407; color: #fdba74; }
[data-theme="dark"] .type-badge.type-life       { background: #3b0764; color: #d8b4fe; }
[data-theme="dark"] .type-badge.type-debt       { background: #450a0a; color: #fca5a5; }
[data-theme="dark"] .type-badge.type-wealth     { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .type-badge.type-goal       { background: #1e1b4b; color: #a5b4fc; }
[data-theme="dark"] .type-badge.type-event      { background: #500724; color: #f9a8d4; }
[data-theme="dark"] .type-badge.type-retirement { background: #451a03; color: #fcd34d; }
[data-theme="dark"] .type-badge.type-project    { background: #083344; color: #67e8f9; }
[data-theme="dark"] .type-badge.type-abstinence { background: #2e1065; color: #c4b5fd; }
[data-theme="dark"] .type-badge.type-money-goal { background: #1a2e05; color: #bef264; }

/* ---------- Widget Styles ---------- */
.widget-page {
  min-height: 100vh;
  background: #0a0f1e;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.widget-card {
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: var(--radius-lg);
  padding: 2.5rem 3rem;
  min-width: 320px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.widget-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
}

.widget-value {
  font-size: 3rem;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace;
  font-weight: 800;
  color: #3b82f6;
  line-height: 1;
  letter-spacing: -0.03em;
}
.widget-value.value-updated {
  animation: pulse-value 0.45s ease-out;
}

.widget-subvalue {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: #475569;
}

/* ---------- Empty State ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4rem 2rem;
  gap: 1rem;
}

.empty-state-icon {
  font-size: 4rem;
  line-height: 1;
  opacity: 0.4;
}

.empty-state-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--color-text);
}

.empty-state-subtitle {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  max-width: 36ch;
  line-height: 1.6;
}

.empty-state .btn {
  margin-top: 0.5rem;
}

/* ---------- Counter Detail Page ---------- */
.counter-detail-value {
  font-size: 4rem;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace;
  font-weight: 800;
  color: var(--color-primary);
  text-align: center;
  line-height: 1;
  letter-spacing: -0.04em;
  padding: 1.5rem 0;
}
.counter-detail-value.value-updated {
  animation: pulse-value 0.45s ease-out;
}

.counter-detail-subvalues {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.counter-detail-subvalue-card {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  text-align: center;
}

.counter-detail-subvalue-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.3rem;
}

.counter-detail-subvalue-number {
  font-size: 1.1rem;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace;
  font-weight: 700;
  color: var(--color-text);
  animation: count-up 0.3s ease-out;
}

/* ---------- Counter Type Selector ---------- */
.type-select-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.625rem;
}

.type-card {
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.85rem 0.75rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
  background: var(--color-surface);
  user-select: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}
.type-card:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  transform: translateY(-1px);
}
.type-card.selected {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

[data-theme="dark"] .type-card:hover,
[data-theme="dark"] .type-card.selected {
  background: rgba(59, 130, 246, 0.1);
}

.type-card-icon {
  font-size: 1.5rem;
  line-height: 1;
}
.type-card-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-text-muted);
  line-height: 1.2;
}
.type-card.selected .type-card-label {
  color: var(--color-primary);
  font-weight: 600;
}

/* ---------- Responsive — Mobile ---------- */
@media (max-width: 640px) {
  .counter-grid {
    grid-template-columns: 1fr;
  }

  .counter-tile.tile-large {
    grid-column: span 1;
    padding: 1.25rem;
  }
  .counter-tile.tile-large .counter-tile-value {
    font-size: 2rem;
  }

  .counter-tile-value {
    font-size: 1.5rem;
  }

  .counter-detail-value {
    font-size: 2.75rem;
  }

  .counter-detail-subvalues {
    grid-template-columns: 1fr 1fr;
  }

  .type-select-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }

  .widget-value {
    font-size: 2.25rem;
  }

  .widget-card {
    padding: 2rem 1.5rem;
    min-width: 0;
    width: 100%;
  }
}


/* ============================================================
   Mobile-First Erweiterungen & PWA-Verbesserungen
   ============================================================ */

/* ---------- Basis: Etwas größere Schrift auf Mobilgeräten ---------- */
@media (max-width: 768px) {
  html {
    font-size: 17px;
  }
}

/* ---------- Sidebar: Overlay-Backdrop (Mobilgerät) ---------- */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 99;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.sidebar-backdrop.active {
  display: block;
}

/* Klasse zum Öffnen der Sidebar per JavaScript */
.sidebar.sidebar-mobile-open {
  transform: translateX(0) !important;
  box-shadow: var(--shadow-lg);
}

/* ---------- Topbar: Kompakt auf Mobilgeräten ---------- */
@media (max-width: 768px) {
  .topbar {
    padding: 0 12px;
    height: 52px;
  }

  .topbar-title {
    font-size: 14px;
  }
}

/* ---------- Counter-Kacheln: Touch-freundliche Ziele ---------- */
@media (max-width: 768px) {
  .counter-grid {
    grid-template-columns: 1fr;
  }

  .counter-tile {
    min-height: 44px;
    /* touch-freundliche Mindesthöhe */
    padding: 1rem;
  }

  .counter-tile-actions .btn {
    min-height: 44px;
    min-width: 44px;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* ---------- Schaltflächen: Größere Touch-Ziele auf Mobilgeräten ---------- */
@media (max-width: 768px) {
  .btn {
    min-height: 44px;
    padding: 10px 18px;
  }

  .btn-sm {
    min-height: 36px;
    padding: 6px 14px;
  }
}

/* ---------- Formulare: Volle Breite auf Mobilgeräten ---------- */
@media (max-width: 768px) {
  .form-input,
  select.form-input,
  textarea.form-input {
    width: 100%;
    font-size: 16px; /* verhindert iOS-Zoom */
  }

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

/* ---------- Dashboard Stats-Grid: Responsive Spalten ---------- */
@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
}

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

/* ---------- Tabellen: Horizontales Scrollen auf Mobilgeräten ---------- */
@media (max-width: 768px) {
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-sm);
  }

  .table {
    min-width: 560px;
  }

  .table th,
  .table td {
    padding: 10px 12px;
    white-space: nowrap;
  }
}

/* ---------- Counter-Detail: Responsive Schriftgröße (clamp) ---------- */
.counter-detail-value {
  font-size: clamp(2rem, 8vw, 4rem);
}

/* ---------- Content-Grid: Einspaltig auf Mobilgeräten ---------- */
@media (max-width: 768px) {
  .content-grid,
  .content-grid-narrow {
    grid-template-columns: 1fr;
  }
}

/* ---------- Auth-Karte: Vollbreite auf sehr kleinen Bildschirmen ---------- */
@media (max-width: 400px) {
  .auth-card {
    padding: 20px 14px;
    border-radius: var(--radius-md);
  }

  .auth-title {
    font-size: 20px;
  }
}

/* ---------- Native <dialog> modal ---------- */
dialog.modal-dialog {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 0;
  width: 100%;
  max-width: 540px;
  animation: modalIn 0.2s ease;
}

dialog.modal-dialog::backdrop {
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
}

.modal-content { display: flex; flex-direction: column; }

.modal-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

/* ---------- API info modal content ---------- */
.api-info-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.api-info-list li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: .9rem;
  line-height: 1.5;
}

.api-info-list li svg { flex-shrink: 0; margin-top: 2px; color: var(--color-primary); }

.api-code-block {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: monospace;
  font-size: .82rem;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0 0 .75rem;
}

.api-info-note {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  background: rgba(59,130,246,.08);
  border: 1px solid rgba(59,130,246,.2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: .85rem;
  margin-top: 1rem;
  color: var(--color-text);
}

.api-info-note svg { flex-shrink: 0; margin-top: 1px; color: var(--color-primary); }

.btn-sm { padding: .25rem .65rem; font-size: .8rem; }

/* ── Form helpers ─────────────────────────────────────────────────────── */
.form-hint {
  display: block;
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .25rem;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .45rem .85rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: .875rem;
  transition: border-color .15s, background .15s;
  background: var(--color-surface);
}

.radio-option:hover {
  border-color: var(--color-primary);
  background: rgba(59,130,246,.06);
}

.radio-option input[type="radio"] {
  accent-color: var(--color-primary);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.radio-option:has(input:checked) {
  border-color: var(--color-primary);
  background: rgba(59,130,246,.1);
  color: var(--color-primary);
  font-weight: 500;
}
