:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-alt: #f8f9fb;
  --text: #171b21;
  --text-muted: #5c6470;
  --border: #e3e6ea;
  --primary: #0d5c56;
  --primary-hover: #0a4842;
  --primary-soft: #e3f2ef;
  --accent: #a9720f;
  --success: #1a7a49;
  --success-soft: #e8f6ee;
  --danger: #b3261e;
  --danger-soft: #fbebea;
  --warning: #92600a;
  --warning-soft: #fdf3e0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(23,27,33,0.06), 0 1px 3px rgba(23,27,33,0.04);
  --shadow-md: 0 8px 24px rgba(23,27,33,0.10);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Consolas, "Roboto Mono", monospace;
}

[data-theme="dark"] {
  --bg: #10151a;
  --surface: #171e24;
  --surface-alt: #1d252c;
  --text: #e7eaee;
  --text-muted: #97a1ad;
  --border: #29323a;
  --primary: #2fa89e;
  --primary-hover: #48c0b6;
  --primary-soft: #123430;
  --accent: #d1a24a;
  --success: #34b374;
  --success-soft: #0f2a1d;
  --danger: #e2665c;
  --danger-soft: #341715;
  --warning: #d9a441;
  --warning-soft: #302407;
  --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 8px 28px rgba(0,0,0,0.5);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.container { max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; }

.mono-accent, .mono-num, .mono-input { font-family: var(--mono); }
.mono-num { font-variant-numeric: tabular-nums; }

/* Topbar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: 14px 20px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-text .mono-accent { color: var(--accent); font-weight: 600; }
.topnav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.topnav a { color: var(--text-muted); font-weight: 500; font-size: 0.94rem; }
.topnav a:hover { color: var(--primary); text-decoration: none; }

.theme-toggle {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: inline-flex; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); }
.stat-card.stat-accent { border-left-color: var(--accent); }
.stat-label { color: var(--text-muted); font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-value { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 2rem; font-weight: 700; margin-top: 6px; }

/* Panel */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.form-panel { max-width: 560px; margin: 0 auto; }
.form-panel h2 { margin-top: 0; }

.search-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.search-input-wrap { position: relative; display: flex; align-items: center; }
.search-input-wrap svg { position: absolute; left: 11px; color: var(--text-muted); pointer-events: none; }
.search-input-wrap input { padding-left: 34px; min-width: 220px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 18px; border-radius: var(--radius-sm); font-weight: 600; font-size: 0.92rem; border: 1px solid transparent; cursor: pointer; transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease; }
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--primary); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); }
.btn-block { width: 100%; }

.btn-icon { background: none; border: none; cursor: pointer; padding: 6px; border-radius: 6px; line-height: 1; color: var(--text-muted); display: inline-flex; align-items: center; }
.btn-icon:hover { background: var(--surface-alt); color: var(--text); }
.btn-danger-icon:hover { background: var(--danger-soft); color: var(--danger); }
.inline-form { display: inline; }

/* Link chip - the short code, treated as a first-class object */
.link-chip { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 0.88rem; background: var(--primary-soft); color: var(--primary); padding: 5px 10px; border-radius: 999px; font-weight: 600; }
.link-chip a { color: inherit; }
.link-chip svg { flex-shrink: 0; }

/* Forms */
label { display: block; font-weight: 600; font-size: 0.88rem; margin: 16px 0 6px; }
label:first-of-type { margin-top: 0; }
input[type="text"], input[type="password"], input[type="url"], input[type="email"] {
  width: 100%; padding: 11px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-alt); color: var(--text); font-size: 0.95rem;
}
input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.short-url-display { display: flex; align-items: center; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-alt); }
.short-url-display span { padding: 11px 0 11px 13px; color: var(--text-muted); white-space: nowrap; font-size: 0.95rem; }
.short-url-display input { border: none; background: transparent; flex: 1; }
.short-url-display input:focus { box-shadow: none; }
.form-actions { margin-top: 20px; display: flex; gap: 10px; }
.form-section-title { margin: 22px 0 4px; font-size: 0.95rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; border-top: 1px solid var(--border); padding-top: 16px; }
.form-section-title:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }

/* Alerts */
.alert { padding: 13px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 0.92rem; }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }

/* Table */
.table-wrap { overflow-x: auto; }
.links-table { width: 100%; border-collapse: collapse; }
.links-table th, .links-table td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--border); font-size: 0.92rem; vertical-align: middle; }
.links-table th { color: var(--text-muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
.truncate { display: inline-block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; color: var(--text-muted); }
.actions-cell { white-space: nowrap; }
.empty-state { color: var(--text-muted); text-align: center; padding: 40px 0; }

/* Pagination */
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.page-link { padding: 6px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); color: var(--text); font-size: 0.88rem; }
.page-link:hover { border-color: var(--primary); text-decoration: none; }
.page-link.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Auth / install */
.auth-wrap { min-height: calc(100vh - 40px); display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 32px 28px; width: 100%; max-width: 400px; }
.install-card { max-width: 460px; }
.auth-brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.2rem; color: var(--text); margin-bottom: 2px; }
.auth-title { margin: 0 0 4px; font-size: 1.3rem; }
.muted-small { color: var(--text-muted); font-size: 0.85rem; margin: 4px 0 16px; }

/* 404 */
.notfound-wrap { min-height: 50vh; display: flex; align-items: center; justify-content: center; }
.notfound-card { text-align: center; color: var(--text); }
.notfound-card h1 { font-family: var(--mono); font-size: 4rem; margin: 0; color: var(--primary); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(10,12,15,0.55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-content { background: var(--surface); border-radius: var(--radius); padding: 24px; text-align: center; position: relative; max-width: 320px; width: 100%; box-shadow: var(--shadow-md); }
.modal-content h3 { margin-top: 0; }
.modal-close { position: absolute; top: 10px; right: 10px; background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 6px; border-radius: 6px; display: inline-flex; }
.modal-close:hover { background: var(--surface-alt); color: var(--text); }
#qrImageWrap { margin: 12px 0; }
#qrImageWrap img { max-width: 100%; border-radius: 8px; background: #fff; padding: 8px; }

code { background: var(--surface-alt); padding: 2px 6px; border-radius: 4px; font-size: 0.88em; font-family: var(--mono); }

/* Responsive table -> stacked cards */
@media (max-width: 700px) {
  .links-table thead { display: none; }
  .links-table, .links-table tbody, .links-table tr, .links-table td { display: block; width: 100%; }
  .links-table tr { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 12px; padding: 8px 12px; }
  .links-table td { border-bottom: none; padding: 8px 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
  .links-table td::before { content: attr(data-label); font-weight: 600; color: var(--text-muted); font-size: 0.72rem; text-transform: uppercase; }
  .truncate { max-width: 160px; }
  .panel-header { flex-direction: column; align-items: stretch; }
  .search-form { width: 100%; }
  .search-input-wrap { flex: 1; }
  .search-input-wrap input { width: 100%; min-width: 0; }
}

.modal[hidden]{display:none;}