/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  --primary:       #6366f1;
  --primary-dark:  #4f46e5;
  --primary-light: #eef2ff;
  --danger:        #ef4444;
  --danger-dark:   #dc2626;
  --success:       #22c55e;
  --warning:       #f59e0b;

  --bg:       #f1f5f9;
  --surface:  #ffffff;
  --surface-2:#f8fafc;
  --border:   #e2e8f0;
  --text:     #1e293b;
  --muted:    #64748b;
  --shadow:   0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:0 4px 16px rgba(0,0,0,.10);
  --radius:   12px;
  --header-h: 60px;
}

[data-theme="dark"] {
  --bg:       #0f172a;
  --surface:  #1e293b;
  --surface-2:#162032;
  --border:   #334155;
  --text:     #f1f5f9;
  --muted:    #94a3b8;
  --shadow:   0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow-md:0 4px 16px rgba(0,0,0,.35);
  --primary-light: #1e1b4b;
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background .3s, color .3s;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
label { font-size: .875rem; font-weight: 600; color: var(--muted); display: block; margin-bottom: .35rem; }
p { margin: 0; }
h2 { font-size: 1.5rem; font-weight: 700; }
h3 { font-size: 1.15rem; font-weight: 700; }

/* ── Header ────────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  gap: 1rem;
}
.header-left  { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.header-right { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }
.logo         { font-weight: 800; font-size: 1.1rem; white-space: nowrap; }
.header-sep   { color: var(--border); }
.header-username {
  font-weight: 700;
  color: var(--primary);
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Main / Content ────────────────────────────────────────── */
.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}
.content-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.muted { color: var(--muted); font-size: .9rem; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: .15s;
  white-space: nowrap;
  line-height: 1.4;
}
.btn:active { transform: scale(.97); }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-dark); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover   { background: var(--danger-dark); }
.btn-outline  { background: transparent; border: 2px solid var(--border); color: var(--text); }
.btn-outline:hover  { border-color: var(--primary); color: var(--primary); }
.btn-ghost    { background: transparent; color: var(--muted); }
.btn-ghost:hover    { background: var(--surface-2); color: var(--text); }
.btn-icon     { background: transparent; color: var(--muted); padding: .5rem; font-size: 1.1rem; }
.btn-icon:hover     { background: var(--surface-2); }
.btn-full     { width: 100%; justify-content: center; padding: .7rem; }
.btn-sm       { padding: .3rem .7rem; font-size: .8rem; }

/* ── Inputs ────────────────────────────────────────────────── */
.input {
  width: 100%;
  padding: .6rem .9rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: .95rem;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: .2s;
  font-family: inherit;
}
.input:focus  { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
.textarea     { resize: vertical; min-height: 160px; line-height: 1.6; }
.form-group   { margin-bottom: 1rem; }
.hint         { font-weight: 400; font-size: .8rem; }

/* ── Notes Grid ────────────────────────────────────────────── */
.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.note-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.1rem .8rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: .5rem;
  transition: box-shadow .2s, transform .2s;
  animation: fadeIn .25s ease;
}
.note-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.note-title {
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.35;
  word-break: break-word;
}
.note-content {
  color: var(--muted);
  font-size: .875rem;
  flex: 1;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 100px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}
.note-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: .25rem;
}
.note-date { font-size: .75rem; color: var(--muted); }
.note-actions { display: flex; gap: .3rem; }
.note-actions .btn { padding: .3rem .6rem; font-size: .78rem; }

/* ── State Boxes ───────────────────────────────────────────── */
.state-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  padding: 3rem 1rem;
  text-align: center;
}
.state-icon { font-size: 3rem; }

/* ── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .25rem .7rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
}
.badge-locked   { background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.badge-unlocked { background: #dcfce7; border: 1px solid #86efac; color: #166534; }
[data-theme="dark"] .badge-unlocked { background: #14532d; border-color: #166534; color: #86efac; }

/* ── PIN Modal ─────────────────────────────────────────────── */
.pin-dots {
  display: flex;
  gap: .75rem;
  justify-content: center;
  margin: 1rem 0 .5rem;
}
.pin-dots span {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--border);
  transition: background .15s;
}
.pin-dots span.filled { background: var(--primary); }

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  margin: 1rem 0;
}
.pin-pad button {
  padding: .9rem;
  font-size: 1.2rem;
  font-weight: 700;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: .15s;
}
.pin-pad button:hover  { border-color: var(--primary); background: var(--primary-light); }
.pin-pad button:active { transform: scale(.93); }
.pin-clear { color: var(--danger) !important; }
.pin-ok    { background: var(--primary) !important; color: #fff !important; border-color: var(--primary) !important; }
.pin-ok:hover { background: var(--primary-dark) !important; }

/* ── Modal Overlay ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn .2s ease;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.75rem;
  width: 100%;
  max-width: 420px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  animation: slideUp .25s ease;
}
.modal-large  { max-width: 620px; }
.modal-small  { max-width: 360px; }
.modal h3     { margin-bottom: .5rem; }
.modal .muted { margin-bottom: 1rem; }
.modal-close {
  position: absolute;
  top: 1rem; right: 1rem;
  background: transparent;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--muted);
  padding: .25rem .5rem;
  border-radius: 6px;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }

/* ── Admin: Login ──────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  text-align: center;
}
.login-logo { font-size: 2.5rem; margin-bottom: .75rem; }
.login-card h2 { margin-bottom: .25rem; }
.login-card .muted { margin-bottom: 1.5rem; }
.login-card .form-group { text-align: left; }

/* ── Admin: Stats ──────────────────────────────────────────── */
.stats-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  flex: 1;
  min-width: 140px;
  box-shadow: var(--shadow);
}
.stat-number { font-size: 2rem; font-weight: 800; color: var(--primary); }
.stat-label  { font-size: .85rem; color: var(--muted); font-weight: 500; }

/* ── Admin: Card & Table ───────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.card-header h3 { margin: 0; }

.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table thead tr { background: var(--surface-2); }
.table th {
  padding: .75rem 1rem;
  text-align: left;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.table td { padding: .85rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }

.user-name { font-weight: 700; }
.user-link { font-size: .8rem; color: var(--primary); }
.user-link:hover { text-decoration: underline; }
.badge-notes {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 700;
}
.url-preview {
  margin-top: .4rem;
  padding: .4rem .7rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .8rem;
  color: var(--primary);
  word-break: break-all;
  font-family: monospace;
}

/* ── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #f1f5f9;
  padding: .7rem 1.4rem;
  border-radius: 999px;
  font-size: .875rem;
  font-weight: 600;
  box-shadow: 0 8px 30px rgba(0,0,0,.25);
  z-index: 999;
  animation: slideUp .25s ease;
  white-space: nowrap;
}
.toast.success { background: #166534; }
.toast.error   { background: #991b1b; }

/* ── Error text ────────────────────────────────────────────── */
.error-text { color: var(--danger); font-size: .85rem; margin-top: .5rem; }

/* ── Spinner ───────────────────────────────────────────────── */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ── Utilities ─────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Animations ────────────────────────────────────────────── */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin    { to { transform: rotate(360deg); } }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 640px) {
  .header-inner { padding: 0 .75rem; }
  .main { padding: 1.25rem .75rem 3rem; }
  .modal { padding: 1.25rem; }
  .table th:nth-child(4), .table td:nth-child(4) { display: none; }
  .content-header { align-items: flex-start; flex-direction: column; }
  .header-right .btn-ghost { display: none; }
}
