:root {
  --color-bg: #f1f5f9;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-border-strong: #cbd5e1;
  --color-text: #0f172a;
  --color-text-muted: #64748b;
  --color-text-subtle: #94a3b8;
  --color-accent: #4f46e5;
  --color-accent-hover: #4338ca;
  --color-accent-soft: #eef2ff;
  --color-danger: #dc2626;
  --color-danger-soft: #fef2f2;
  --color-success: #059669;
  --color-success-soft: #ecfdf5;
  --color-warning-soft: #fffbeb;
  --color-warning-border: #fcd34d;
  --sidebar-width: 240px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.12);
  --font-sans: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  background: var(--color-bg);
  color: var(--color-text);
}

a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ── Login page ── */

body.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(145deg, #eef2ff 0%, #f8fafc 45%, #f1f5f9 100%);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 2rem;
}

.login-brand {
  text-align: center;
  margin-bottom: 1.75rem;
}

.login-brand__logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--color-accent);
  color: #fff;
  font-weight: 700;
  font-size: 1.25rem;
  margin-bottom: 0.75rem;
}

.login-brand__title {
  margin: 0 0 0.35rem;
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.login-brand__subtitle {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 0.9375rem;
}

/* ── App shell (authenticated) ── */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-text);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar__brand {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar__brand-name {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}

.sidebar__brand-tag {
  margin: 0.2rem 0 0;
  font-size: 0.75rem;
  color: var(--color-text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar__nav {
  flex: 1;
  padding: 0.75rem 0.625rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-sm);
  color: #cbd5e1;
  font-weight: 500;
  font-size: 0.9375rem;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.sidebar__link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  text-decoration: none;
}

.sidebar__link--active {
  background: var(--color-accent);
  color: #fff;
}

.sidebar__link--active:hover {
  background: var(--color-accent-hover);
  color: #fff;
}

.sidebar__link svg {
  flex-shrink: 0;
  opacity: 0.85;
}

.sidebar__footer {
  padding: 0.75rem 0.625rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar__logout {
  width: 100%;
}

.main-content {
  flex: 1;
  min-width: 0;
  padding: 2rem 2.25rem;
}

.page-header {
  margin-bottom: 1.5rem;
}

.page-header__title {
  margin: 0 0 0.25rem;
  font-size: 1.625rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-header__desc {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 0.9375rem;
}

/* ── Flash messages ── */

.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  font-size: 0.9375rem;
  border: 1px solid transparent;
}

.flash--error {
  background: var(--color-danger-soft);
  border-color: #fecaca;
  color: #991b1b;
}

.flash--success {
  background: var(--color-success-soft);
  border-color: #a7f3d0;
  color: #065f46;
}

.flash--info {
  background: var(--color-warning-soft);
  border-color: var(--color-warning-border);
  color: #92400e;
}

/* ── Stats row ── */

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.125rem 1.25rem;
  box-shadow: var(--shadow-sm);
}

.stat-card__label {
  margin: 0 0 0.35rem;
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

.stat-card__value {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-text);
}

/* ── Forms ── */

.form-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  max-width: 560px;
}

.form-card--wide {
  max-width: 640px;
}

.form-card__actions {
  margin-top: 0.5rem;
  padding-top: 0.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.input-group {
  margin-bottom: 1.125rem;
}

.input-group:last-of-type {
  margin-bottom: 1.25rem;
}

.input-group label,
.input-group__label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--color-text);
}

.input-group input[type="email"],
.input-group input[type="url"],
.input-group input[type="text"],
.input-group input[type="password"] {
  width: 100%;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.75rem;
  font-size: 0.9375rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-group input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
}

.input-group__hint {
  margin: 0.35rem 0 0;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.slug-preview {
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--color-accent-soft);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: var(--color-accent-hover);
  word-break: break-all;
}

.slug-preview__label {
  font-weight: 600;
  color: var(--color-text-muted);
  margin-right: 0.35rem;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 2.75rem;
}

.password-toggle {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.password-toggle:hover {
  color: var(--color-text);
  background: var(--color-bg);
}

.password-toggle:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

.password-toggle svg {
  width: 18px;
  height: 18px;
}

.password-toggle .icon-eye-off {
  display: none;
}

.password-toggle[aria-pressed="true"] .icon-eye {
  display: none;
}

.password-toggle[aria-pressed="true"] .icon-eye-off {
  display: block;
}

/* ── Buttons ── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.55rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  line-height: 1.25;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.btn:hover {
  text-decoration: none;
}

.btn--primary {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}

.btn--primary:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
  color: #fff;
}

.btn--secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}

.btn--secondary:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.btn--ghost {
  background: transparent;
  color: #cbd5e1;
  border-color: rgba(255, 255, 255, 0.15);
}

.btn--ghost:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.btn--danger {
  background: var(--color-surface);
  color: var(--color-danger);
  border-color: #fecaca;
}

.btn--danger:hover {
  background: var(--color-danger-soft);
  color: var(--color-danger);
}

.btn--sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8125rem;
}

.btn--block {
  width: 100%;
}

.btn--copied {
  background: var(--color-success-soft) !important;
  color: var(--color-success) !important;
  border-color: #a7f3d0 !important;
}

/* ── Table ── */

.table-wrap {
  overflow-x: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

thead th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

tbody td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: #fafbfc;
}

.slug-cell {
  font-weight: 600;
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  font-size: 0.875rem;
}

.url-cell {
  max-width: 280px;
}

.url-cell a {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

.url-cell a:hover {
  color: var(--color-accent);
}

.click-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--color-accent-soft);
  color: var(--color-accent-hover);
  font-weight: 600;
  font-size: 0.8125rem;
}

.date-cell {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.qr-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
}

.qr-card img {
  width: 72px;
  height: 72px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: #fff;
}

.qr-card a {
  font-size: 0.75rem;
  font-weight: 600;
}

.action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.action-group form {
  margin: 0;
  display: inline;
}

/* ── Empty state ── */

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
}

.empty-state__icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  opacity: 0.4;
}

.empty-state__title {
  margin: 0 0 0.5rem;
  font-size: 1.125rem;
  font-weight: 600;
}

.empty-state__desc {
  margin: 0 0 1.25rem;
  color: var(--color-text-muted);
  font-size: 0.9375rem;
}

/* ── Settings section ── */

.settings-section__title {
  margin: 0 0 0.35rem;
  font-size: 1.0625rem;
  font-weight: 600;
}

.settings-section__desc {
  margin: 0 0 1.25rem;
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

/* ── Guest / error pages ── */

.guest-content {
  max-width: 480px;
}

.guest-content p {
  color: var(--color-text-muted);
}

.login-card--wide {
  max-width: 720px;
}

.public-links-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.public-links-item {
  display: grid;
  grid-template-columns: minmax(120px, 0.35fr) 1fr;
  gap: 1rem;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

.public-links-item:last-child {
  border-bottom: none;
}

.public-links-item:nth-child(even) {
  background: #f8fafc;
}

.public-links-item__label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
  margin-bottom: 0.25rem;
}

.public-links-item__short {
  font-weight: 600;
  color: var(--color-accent);
  word-break: break-word;
}

.public-links-item__url {
  color: var(--color-text-muted);
  font-size: 0.9375rem;
  word-break: break-all;
}

.public-links-item__url:hover {
  color: var(--color-accent);
}

.public-links-empty {
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--color-text-muted);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  background: #f8fafc;
}

.public-links-empty p {
  margin: 0;
}

.public-links-footer {
  margin: 1.25rem 0 0;
  text-align: center;
  font-size: 0.875rem;
}

.public-links-footer a {
  color: var(--color-text-muted);
}

.public-links-footer a:hover {
  color: var(--color-accent);
}

@media (max-width: 560px) {
  .public-links-item {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
}

/* ── Responsive ── */

@media (max-width: 768px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .sidebar__brand {
    flex: 1;
    min-width: 140px;
    border-bottom: none;
    padding: 0.875rem 1rem;
  }

  .sidebar__nav {
    flex: none;
    width: 100%;
    order: 3;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 0 0.5rem 0.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }

  .sidebar__footer {
    flex: none;
    border-top: none;
    padding: 0.875rem 1rem;
    width: auto;
  }

  .sidebar__logout {
    width: auto;
  }

  .main-content {
    padding: 1.25rem 1rem 2rem;
  }

  .page-header__title {
    font-size: 1.375rem;
  }

  .login-card {
    padding: 1.5rem;
  }
}
