/* ===== VARIABLES ===== */
:root {
  --primary:       #6c63ff;
  --primary-dark:  #5a52d5;
  --accent:        #ff6b9d;
  --secondary:     #43e97b;
  --fun-pop:       #ffd93d;
  --bg:            #f5f4ff;
  --surface:       #ffffff;
  --surface-2:     #f0eeff;
  --text:          #2d2b55;
  --text-muted:    #7c7a9e;
  --border:        #ddd9ff;
  --shadow:        0 8px 32px rgba(108, 99, 255, 0.15);
  --shadow-hover:  0 16px 48px rgba(108, 99, 255, 0.25);
  --radius:        16px;
  --radius-sm:     10px;
  --radius-pill:   50px;
}

body.dark-mode {
  --bg:            #0f0e1a;
  --surface:       #1a1830;
  --surface-2:     #231f3d;
  --text:          #e8e6ff;
  --text-muted:    #9d9bbf;
  --border:        #2e2b4e;
  --shadow:        0 8px 32px rgba(108, 99, 255, 0.30);
  --shadow-hover:  0 16px 48px rgba(108, 99, 255, 0.45);
}

/* ===== BASE ===== */
*, *::before, *::after { box-sizing: border-box; }

body {
  background-color: var(--bg);
  color:            var(--text);
  font-family:      'Poppins', sans-serif;
  min-height:       100vh;
  display:          flex;
  flex-direction:   column;
  transition:       background-color 0.3s ease, color 0.3s ease;
}

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

/* ===== ANIMATIONS ===== */
@keyframes wiggle {
  0%, 100% { transform: rotate(-6deg); }
  50%       { transform: rotate(6deg);  }
}
@keyframes float {
  0%, 100% { transform: translateY(0);     }
  50%       { transform: translateY(-8px); }
}
@keyframes slide-up {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0);    }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.icon-wiggle { animation: wiggle 1.8s ease-in-out infinite; display: inline-block; }
.icon-float  { animation: float  3s   ease-in-out infinite; display: inline-block; }
.animate-in  { animation: slide-up 0.4s ease both; }

/* ===== HERO ===== */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color:      #fff;
  padding:    5rem 0;
  position:   relative;
  overflow:   hidden;
}
.hero::before {
  content:    '';
  position:   absolute;
  inset:      0;
  background: radial-gradient(circle at 25% 35%, rgba(255,255,255,0.08) 0%, transparent 50%),
              radial-gradient(circle at 75% 70%, rgba(255,255,255,0.05) 0%, transparent 40%);
  pointer-events: none;
}

/* ===== CARDS ===== */
.card {
  background:    var(--surface);
  border:        2px solid var(--border);
  border-radius: var(--radius);
  box-shadow:    var(--shadow);
  transition:    transform 0.2s ease, box-shadow 0.2s ease;
  color:         var(--text);
}
.card:hover {
  transform:  translateY(-4px);
  box-shadow: var(--shadow-hover);
}

.scribble-border {
  border:        2.5px solid var(--primary) !important;
  border-radius: var(--radius) !important;
  position:      relative;
}
.scribble-border::after {
  content:       '';
  position:      absolute;
  inset:         -4px;
  border:        2px dashed var(--accent);
  border-radius: calc(var(--radius) + 4px);
  opacity:       0.35;
  pointer-events: none;
}

.readable-text {
  color:       var(--text-muted);
  font-size:   0.92rem;
  line-height: 1.65;
}

/* ===== BUTTONS ===== */
.btn-primary {
  background:     linear-gradient(135deg, var(--primary), var(--accent));
  border:         none;
  border-radius:  var(--radius-pill);
  font-weight:    600;
  letter-spacing: 0.03em;
  transition:     transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s;
}
.btn-primary:hover:not(:disabled) {
  background:  linear-gradient(135deg, var(--primary), var(--accent));
  transform:   translateY(-2px);
  box-shadow:  0 8px 24px rgba(108, 99, 255, 0.4);
  opacity:     0.9;
}
.btn-primary:active  { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.65; cursor: not-allowed; }

.btn-outline-light { border-radius: var(--radius-pill); font-weight: 500; }

.auth-btn {
  border-radius:  var(--radius-pill) !important;
  font-weight:    600;
  letter-spacing: 0.03em;
  transition:     transform 0.15s ease, box-shadow 0.15s ease;
}
.auth-btn:hover { transform: translateY(-2px); }

/* ===== AUTH PAGE LAYOUT ===== */
.auth-page {
  min-height: calc(100vh - 160px);
  display:    flex;
  align-items: center;
  padding:    2rem 0;
  position:   relative;
}
.auth-page::before {
  content:  '';
  position: fixed;
  inset:    0;
  background:
    radial-gradient(circle at 15% 50%, rgba(108, 99, 255, 0.07) 0%, transparent 55%),
    radial-gradient(circle at 85% 15%, rgba(255, 107, 157, 0.07) 0%, transparent 45%),
    radial-gradient(circle at 55% 85%, rgba(67, 233, 123, 0.05) 0%, transparent 40%);
  pointer-events: none;
  z-index: 0;
}
.auth-page > .container { position: relative; z-index: 1; }

/* ===== AUTH CARD ===== */
.auth-card {
  background:    var(--surface);
  border:        1.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow:    var(--shadow);
  padding:       2.5rem 2.75rem;
  max-width:     480px;
  margin:        0 auto;
  animation:     slide-up 0.4s ease both;
}
@media (max-width: 576px) {
  .auth-card { padding: 2rem 1.5rem; }
}

.auth-brand {
  font-family: 'Permanent Marker', cursive;
  font-size:   2rem;
  background:  linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  display: inline-block;
}

.auth-card h2 {
  font-size:     1.45rem;
  font-weight:   700;
  color:         var(--text);
  margin-bottom: 0.2rem;
}
.auth-subtitle {
  color:         var(--text-muted);
  font-size:     0.9rem;
  margin-bottom: 1.75rem;
}

/* ===== FORM CONTROLS ===== */
.form-label {
  color:         var(--text);
  font-weight:   500;
  font-size:     0.88rem;
  margin-bottom: 0.35rem;
}

.form-control {
  background:    var(--surface-2);
  border:        1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color:         var(--text);
  font-size:     0.95rem;
  padding:       0.65rem 1rem;
  transition:    border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.form-control::placeholder { color: var(--text-muted); opacity: 0.7; }
.form-control:focus {
  background:   var(--surface);
  border-color: var(--primary);
  box-shadow:   0 0 0 3px rgba(108, 99, 255, 0.18);
  color:        var(--text);
  outline:      none;
}
.form-control.is-invalid {
  border-color: var(--accent);
  box-shadow:   0 0 0 3px rgba(255, 107, 157, 0.15);
}
.invalid-feedback { color: var(--accent); font-size: 0.8rem; }

/* Password toggle */
.password-wrapper           { position: relative; }
.password-wrapper .form-control { padding-right: 3rem; }
.password-toggle {
  position:   absolute;
  right:      0.9rem;
  top:        50%;
  transform:  translateY(-50%);
  background: none;
  border:     none;
  color:      var(--text-muted);
  cursor:     pointer;
  padding:    0;
  font-size:  1rem;
  line-height: 1;
  transition: color 0.15s;
  z-index:    5;
}
.password-toggle:hover { color: var(--primary); }

/* ===== PASSWORD STRENGTH ===== */
.strength-bar {
  height:        4px;
  border-radius: 4px;
  background:    var(--border);
  margin-top:    0.4rem;
  overflow:      hidden;
}
.strength-fill {
  height:     100%;
  border-radius: 4px;
  width:      0%;
  transition: width 0.35s ease, background 0.35s ease;
}
.strength-fill.weak   { width: 33%; background: var(--accent);    }
.strength-fill.medium { width: 66%; background: var(--fun-pop);   }
.strength-fill.strong { width: 100%; background: var(--secondary); }

.strength-label {
  font-size:  0.78rem;
  color:      var(--text-muted);
  margin-top: 0.2rem;
  min-height: 1.1rem;
}

/* ===== CHECKBOXES ===== */
.form-check-input {
  border-color:     var(--border);
  background-color: var(--surface-2);
}
.form-check-input:checked {
  background-color: var(--primary);
  border-color:     var(--primary);
}
.form-check-label { color: var(--text-muted); font-size: 0.88rem; }

/* ===== ALERTS ===== */
.alert { border-radius: var(--radius-sm); font-size: 0.9rem; }
.alert-danger {
  background:   rgba(255, 107, 157, 0.12);
  border-color: rgba(255, 107, 157, 0.4);
  color:        var(--text);
}
.alert-success {
  background:   rgba(67, 233, 123, 0.12);
  border-color: rgba(67, 233, 123, 0.4);
  color:        var(--text);
}

/* ===== AUTH DIVIDER ===== */
.auth-divider {
  display:     flex;
  align-items: center;
  gap:         0.75rem;
  color:       var(--text-muted);
  font-size:   0.83rem;
  margin:      1.25rem 0;
}
.auth-divider::before,
.auth-divider::after {
  content:    '';
  flex:       1;
  height:     1px;
  background: var(--border);
}

/* ===== SPINNER ===== */
.btn-spinner {
  width:        1rem;
  height:       1rem;
  border:       2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation:    spin 0.6s linear infinite;
  display:      inline-block;
  vertical-align: middle;
  margin-right: 0.4rem;
}

/* ===== DASHBOARD ===== */
.stat-card {
  background:    var(--surface);
  border:        1.5px solid var(--border);
  border-radius: var(--radius);
  padding:       1.5rem;
  box-shadow:    var(--shadow);
  transition:    transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover {
  transform:  translateY(-3px);
  box-shadow: var(--shadow-hover);
}
.stat-icon {
  width:           52px;
  height:          52px;
  border-radius:   var(--radius-sm);
  display:         flex;
  align-items:     center;
  justify-content: center;
  font-size:       1.4rem;
  margin-bottom:   1rem;
}
.stat-value {
  font-size:   2rem;
  font-weight: 700;
  line-height: 1;
  color:       var(--text);
}
.stat-label {
  font-size:  0.85rem;
  color:      var(--text-muted);
  margin-top: 0.25rem;
}

/* ===== KEY / TOKEN DISPLAY ===== */
.key-box {
  background:    var(--surface-2);
  border:        1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  font-family:   'Courier New', monospace;
  font-size:     0.85rem;
  word-break:    break-all;
  padding:       0.65rem 0.85rem;
  display:       flex;
  align-items:   center;
  gap:           0.6rem;
}

/* ===== MASTER KEY CARD ===== */
.master-key-card {
  position:   relative;
  overflow:   hidden;
  border-color: rgba(255, 107, 157, 0.35) !important;
  background: linear-gradient(135deg, rgba(255, 107, 157, 0.07), rgba(255, 217, 61, 0.05));
}
.master-key-card::before {
  content:    '';
  position:   absolute;
  left: 0; top: 0; bottom: 0;
  width:      4px;
  background: linear-gradient(180deg, var(--accent), var(--fun-pop));
}
.master-key-badge {
  display:        inline-flex;
  align-items:    center;
  gap:            0.3rem;
  font-size:      0.68rem;
  font-weight:    700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color:          var(--accent);
  background:     rgba(255, 107, 157, 0.14);
  border-radius:  var(--radius-pill);
  padding:        0.2rem 0.6rem;
}

/* ===== DARK MODE OVERRIDES ===== */
body.dark-mode .modal-content {
  background:   var(--surface);
  border-color: var(--border);
  color:        var(--text);
}
body.dark-mode .modal-header   { border-bottom-color: var(--border); }
body.dark-mode .btn-close      { filter: invert(1); }
body.dark-mode .text-muted     { color: var(--text-muted) !important; }
body.dark-mode footer.bg-dark  { background: #060510 !important; }

body.dark-mode .form-control {
  background:   var(--surface-2);
  border-color: var(--border);
  color:        var(--text);
}
body.dark-mode .form-control::placeholder { color: var(--text-muted); opacity: 0.55; }

body.dark-mode .input-group-text {
  background:   var(--surface-2);
  border-color: var(--border);
  color:        var(--text-muted);
}

/* ===== TABLES (dark mode) ===== */
body.dark-mode .table {
  --bs-table-color:       var(--text);
  --bs-table-bg:          var(--surface);
  --bs-table-border-color: var(--border);
  --bs-table-hover-bg:    var(--surface-2);
  --bs-table-striped-bg:  var(--surface-2);
  color: var(--text);
}
body.dark-mode .table > :not(caption) > * > * {
  background-color: transparent;
  color: var(--text);
  border-bottom-color: var(--border);
}
body.dark-mode .table thead th {
  color: var(--text-muted);
  border-bottom-color: var(--border);
}
.table thead th {
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
}

/* ===== DROPDOWN (dark mode) ===== */
body.dark-mode .dropdown-menu {
  background:   var(--surface);
  border-color: var(--border);
  box-shadow:   var(--shadow);
}
body.dark-mode .dropdown-item {
  color: var(--text);
}
body.dark-mode .dropdown-item:hover, body.dark-mode .dropdown-item:focus {
  background: var(--surface-2);
  color: var(--text);
}
body.dark-mode .dropdown-divider  { border-color: var(--border); }
body.dark-mode .dropdown-header   { color: var(--text-muted); }

/* ===== SELECT ===== */
.form-select {
  background-color: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}
.form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108,99,255,.18);
}
body.dark-mode .form-select {
  background-color: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}
