/*
 * SJC Link Manager - styles
 *
 * Tokens, the login card and the building blocks come from
 * SJC-medical-application (same school brand, from SJC-phonebook-app).
 * The app shell is simpler: one top bar, no side or bottom nav.
 */
:root {
  --maroon: #7a0019;
  --maroon-dark: #4a0010;
  --maroon-light: #a3123a;
  --blue: #185fa5;
  --blue-dark: #0c447c;
  --blue-light: #2f7fc7;
  --gold: #dab44b;
  --gold-dark: #b8923a;
  --amber: #854f0b;
  --amber-bg: #faeeda;
  --red-bg: #fcebeb;
  --red-text: #501313;
  --green: #1e6b3a;
  --green-bg: #e3f3e8;
  --bg: #f2f3f6;
  --surface: #ffffff;
  --border: #e4e4e8;
  --text: #1c1c1e;
  --text-muted: #6b6b70;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 3px rgba(20, 20, 30, 0.08);
  --shadow-md: 0 10px 30px rgba(20, 20, 30, 0.12);
  --topbar-h: 60px;
  --tap: 48px; /* minimum touch target */
}
* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Raleway", system-ui, sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--blue); }

:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* =========================================================
   Public pages (login / denied) - from the phonebook
   ========================================================= */

body.public {
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #fbfbfc 0%, var(--bg) 100%);
  background-image: url("/static/backgrounds/mobile/blue.png");
  background-size: cover;
  background-position: top center;
}

@media (min-width: 900px) {
  body.public { background-image: url("/static/backgrounds/desktop/blue.png"); }
}

.public-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border-top: 3px solid var(--gold);
  box-shadow: var(--shadow-md);
  padding: 40px 28px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  animation: cardIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.login-mark { width: 76px; height: 76px; margin: 0 auto 18px; display: block; }
.login-card h1 { margin: 0 0 6px; font-size: 1.5rem; font-weight: 700; }
.login-card .subtitle { color: var(--text-muted); margin: 0 0 26px; line-height: 1.4; }

.google-login-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 50px; padding: 12px 16px;
  font-family: inherit; font-size: 1rem; font-weight: 500;
  border: 1px solid #e0e0e3; border-radius: var(--radius-md);
  background: #fff; color: var(--text); text-decoration: none;
}
.google-login-btn:hover { background: #f7f7f8; box-shadow: var(--shadow-sm); }
.google-icon { width: 20px; height: 20px; }

.demo-login {
  margin-top: 22px; padding-top: 18px; border-top: 1px dashed var(--border);
}
.demo-login p { margin: 0 0 10px; font-size: 0.85rem; color: var(--text-muted); }
.demo-login form { display: inline-block; margin: 3px; }

.site-footer {
  text-align: center;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.85rem;
}

/* =========================================================
   App shell
   ========================================================= */

.topbar {
  position: sticky; top: 0; z-index: 30;
  min-height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(120deg, var(--blue) 0%, var(--blue-dark) 100%);
  border-bottom: 3px solid var(--gold);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand img { width: 34px; height: 34px; }
.brand span { font-weight: 700; font-size: 1.1rem; letter-spacing: 0.01em; }
.topnav { display: flex; align-items: center; gap: 6px; flex: 1; }
.topnav a:not(.btn) {
  color: #fff; text-decoration: none; font-weight: 600; font-size: 0.92rem;
  padding: 8px 12px; border-radius: 8px; min-height: 40px; display: none; align-items: center;
}
.topnav a:not(.btn):hover, .topnav a[aria-current="page"]:not(.btn) { background: rgba(255, 255, 255, 0.15); }
.topnav .btn { margin-left: auto; }
.topbar-user { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.topbar-user .who { display: none; opacity: 0.9; }
.topbar-user form { margin: 0; }
.link-btn {
  font: inherit; font-weight: 600; color: #fff; background: none; border: 0; cursor: pointer;
  padding: 8px 10px; border-radius: 8px; min-height: 40px;
}
.link-btn:hover { background: rgba(255, 255, 255, 0.15); }
.demo-banner {
  background: var(--amber-bg); color: var(--amber); text-align: center;
  font-size: 0.82rem; font-weight: 600; padding: 6px 12px;
}

.content { padding: 16px 16px 40px; }
.content-inner { max-width: 1280px; margin: 0 auto; }

@media (min-width: 768px) {
  .topnav a:not(.btn) { display: inline-flex; }
  .topnav .btn { margin-left: 0; }
  .topnav { padding-left: 12px; }
  .topbar-user .who { display: inline; }
  .content { padding: 24px 24px 48px; }
}
@media (min-width: 1200px) { .content { padding: 28px 36px 56px; } }

/* =========================================================
   Building blocks (from the medical app)
   ========================================================= */

.page-header {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 12px; margin-bottom: 18px;
}
.page-header h1 { margin: 0; font-size: clamp(1.35rem, 4vw, 1.75rem); font-weight: 700; }
.page-header p { margin: 4px 0 0; color: var(--text-muted); }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.card {
  background: var(--surface); border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm); border: 1px solid var(--border);
  padding: 18px;
}
.card + .card { margin-top: 16px; }
.card h2 { margin: 0 0 12px; font-size: 1.05rem; font-weight: 700; }
.card-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-header h2 { margin: 0; }

.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.grid > .card + .card { margin-top: 0; }
@media (min-width: 860px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
}

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 768px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 14px 16px; box-shadow: var(--shadow-sm);
}
.stat .label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }
.stat .value { font-size: 1.8rem; font-weight: 700; color: var(--blue); line-height: 1.2; }
.stat.warn .value { color: var(--maroon); }
/* --- buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 10px 18px;
  font: inherit; font-weight: 600; font-size: 0.95rem;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn svg { width: 20px; height: 20px; }
.btn-primary { background: linear-gradient(150deg, var(--blue-light), var(--blue-dark)); color: #fff; }
.btn-danger { background: linear-gradient(150deg, var(--maroon-light), var(--maroon-dark)); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--blue); border-color: #c9d9ec; }
.btn-ghost { background: transparent; color: var(--blue); }
.btn:hover { filter: brightness(1.06); }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 6px 12px; font-size: 0.85rem; }
.btn-gold { background: var(--gold); color: var(--maroon-dark); }
.btn:disabled { opacity: 0.6; cursor: progress; }

/* --- chips / badges --- */
.chip {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  background: #eef0f4; color: var(--text-muted); font-size: 0.8rem; font-weight: 600;
}
.chip-alert { background: var(--red-bg); color: var(--maroon); }
.chip-warn { background: var(--amber-bg); color: var(--amber); }
.chip-ok { background: var(--green-bg); color: var(--green); }
.chip-info { background: #e3eefa; color: var(--blue-dark); }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }

/* --- flash messages --- */
.flash { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 14px; font-weight: 500; }
.flash-success { background: var(--green-bg); color: var(--green); }
.flash-error { background: var(--red-bg); color: var(--red-text); }
.flash-info { background: #e3eefa; color: var(--blue-dark); }
.flash ul { margin: 6px 0 0; padding-left: 20px; }

.list-sub { font-size: 0.85rem; color: var(--text-muted); }
.empty { color: var(--text-muted); padding: 12px 0; margin: 0; }

/* --- tables: real tables on tablet/desktop, stacked cards on phone --- */
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th { text-align: left; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); padding: 8px 10px; border-bottom: 2px solid var(--border); }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table-wrap { overflow-x: auto; }

@media (max-width: 767px) {
  .table.stack thead { display: none; }
  .table.stack, .table.stack tbody, .table.stack tr, .table.stack td { display: block; width: 100%; }
  .table.stack tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
  .table.stack td { border: none; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; }
  .table.stack td::before { content: attr(data-label); font-weight: 600; color: var(--text-muted); font-size: 0.82rem; }
  .table.stack td[data-label=""]::before { content: none; }
}

/* --- forms --- */
.form-grid { display: grid; gap: 14px; }
@media (min-width: 768px) { .form-grid.cols-2 { grid-template-columns: 1fr 1fr; } .span-2 { grid-column: 1 / -1; } }
.field label, .field .label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.field .hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }
.input, select.input, textarea.input {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  font: inherit; color: var(--text);
  border: 1px solid #d5d5db; border-radius: var(--radius-sm); background: #fff;
}
textarea.input { min-height: 96px; resize: vertical; }
.input:focus { outline: 2px solid var(--blue-light); outline-offset: -1px; }
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); font-weight: 500; }
.check input { width: 22px; height: 22px; }
.form-actions {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end;
  margin-top: 18px;
}

.search-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.search-bar .input { flex: 1 1 220px; }
.search-bar select.input { flex: 0 1 180px; }

/* --- two-pane layouts (pupil record, consultation form) --- */
.split { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 860px) {
  .split { grid-template-columns: 300px minmax(0, 1fr); align-items: start; }
  .split > .split-aside { position: sticky; top: calc(var(--topbar-h) + 16px); }
}
@media (min-width: 1200px) { .split { grid-template-columns: 340px minmax(0, 1fr); } }
.kv { margin: 0; }
.kv div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 0.92rem; }
.kv div:first-child { border-top: none; }
.kv dt { color: var(--text-muted); font-weight: 600; }
.kv dd { margin: 0; text-align: right; }

/* =========================================================
   Link manager
   ========================================================= */

.code { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-weight: 600; word-break: break-all; }
a.code { text-decoration: none; }
a.code:hover { text-decoration: underline; }
code { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 0.9em; background: #eef0f4; padding: 1px 5px; border-radius: 5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.num { text-align: right; }
.url-cell { max-width: 420px; word-break: break-all; }
.url-cell a { color: var(--text-muted); text-decoration: none; }
.url-cell a:hover { color: var(--blue); text-decoration: underline; }
.links-table td .chip { margin-left: 6px; }
.links-table tr.is-inactive td:not(:last-child) { opacity: 0.6; }
.row-actions { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.row-actions form { display: inline; margin: 0; }
.btn-icon { padding: 6px 9px; }
.btn-icon svg { width: 18px; height: 18px; }
.btn-delete { color: var(--maroon); }
.aside-delete { margin-top: 16px; border-color: #e7c9cf; }
.confirm-card { max-width: 640px; }
.confirm-card .form-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 14px; color: var(--text-muted); font-size: 0.9rem; }
.page-header p .btn-sm { min-height: 30px; padding: 2px 8px; vertical-align: middle; }

/* Edit page: the form is the wide column, details on the right */
@media (min-width: 860px) {
  .split.form-split { grid-template-columns: minmax(0, 1fr) 320px; }
}
.search-bar select.input { flex: 1 1 140px; }

@media (max-width: 767px) {
  .table.stack td.num { text-align: right; }
  .url-cell { max-width: none; }
  .table.stack td.url-cell { flex-direction: column; gap: 2px; }
  .hide-phone { display: none !important; }
  .table.stack td.row-actions { justify-content: flex-end; padding-top: 6px; }
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .login-card { animation: none; }
}
