/* Zedenz Referral Management System — hand-written styles (no CSS framework). */

:root {
  --brand: #0e7490;
  --brand-dark: #155e75;
  --brand-light: #e0f2f1;
  --accent: #14b8a6;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f4f7f9;
  --surface: #ffffff;
  --danger: #b91c1c;
  --danger-light: #fef2f2;
  --success: #047857;
  --success-light: #ecfdf5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.06);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--brand); }
a:hover { color: var(--brand-dark); }

img { max-width: 100%; height: auto; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; color: #0f172a; }
h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 600; }

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

.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 20px; }

/* Header */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.02);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 68px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--ink);
  margin-right: auto;
}
.brand img { width: 42px; height: 42px; }
.brand-name { display: block; font-weight: 700; font-size: 1.15rem; letter-spacing: -0.01em; color: #0f172a; }
.brand-system { display: block; font-size: 0.78rem; color: var(--muted); }

.main-nav ul { display: flex; gap: 4px; list-style: none; margin: 0; padding: 0; }
.main-nav a {
  display: block;
  padding: 8px 14px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 500;
  color: var(--ink);
}
.main-nav a:hover { background: var(--bg); color: var(--brand-dark); }
.main-nav a[aria-current="page"] { background: var(--brand-light); color: var(--brand-dark); }

.user-area { display: flex; align-items: center; gap: 12px; font-size: 0.9rem; color: var(--muted); }
.logout-form { margin: 0; }
.logout-link {
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  font: inherit;
  font-weight: 500;
  color: var(--brand);
  cursor: pointer;
}
.logout-link:hover { border-color: var(--brand); color: var(--brand-dark); text-decoration: underline; }

.nav-toggle { display: none; }

/* Main */

main { flex: 1; padding: 32px 0 48px; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-head h1 { margin: 0; }
.page-head .subtitle { margin: 4px 0 0; color: var(--muted); }

.breadcrumb { font-size: 0.875rem; margin-bottom: 8px; color: var(--muted); }
.breadcrumb a { color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
}
.card > h2:first-child { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  line-height: 1.2;
  background: var(--brand);
  color: #fff;
}
.btn:hover { background: var(--brand-dark); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { background: var(--bg); color: var(--ink); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #991b1b; }
.btn-small { padding: 6px 12px; font-size: 0.85rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

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

/* Tables */

.table-wrap { overflow-x: auto; }

table.data { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.data th, table.data td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; background: #f8fafc; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr[data-href] { cursor: pointer; }
table.data tbody tr:hover td { background: #f0fdfa; }
table.data td a { font-weight: 600; text-decoration: none; }
table.data td a:hover { text-decoration: underline; }
td.num, th.num { width: 1%; white-space: nowrap; color: var(--muted); }
td.nowrap { white-space: nowrap; }

.empty { color: var(--muted); padding: 24px 0; text-align: center; }

/* Detail lists */

dl.details { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; margin: 0; }
dl.details dt, dl.details dd { padding: 12px 0; border-bottom: 1px solid var(--line); margin: 0; }
dl.details dt { color: var(--muted); font-weight: 500; padding-right: 16px; }
dl.details > :nth-last-child(-n+2) { border-bottom: none; }
.note { white-space: pre-wrap; overflow-wrap: anywhere; }
.muted { color: var(--muted); }

.doc-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  background: #fff;
}
.doc-link:hover { border-color: var(--brand); background: #f0fdfa; }
.doc-link svg { width: 32px; height: 32px; flex-shrink: 0; }

/* Forms */

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 24px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.wide { grid-column: 1 / -1; }
.field label { font-weight: 600; font-size: 0.92rem; }
.field .required { color: var(--danger); margin-left: 2px; }
.field .help { font-size: 0.82rem; color: var(--muted); }
.field input[type="text"], .field input[type="tel"], .field input[type="date"],
.field input[type="password"], .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}
.field textarea { resize: vertical; min-height: 90px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.25); }
.field input[type="file"] { font: inherit; font-size: 0.9rem; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.errorlist { list-style: none; margin: 0; padding: 0; color: var(--danger); font-size: 0.85rem; }
.form-errors { background: var(--danger-light); color: var(--danger); border: 1px solid #fecaca; border-radius: 8px; padding: 12px 16px; margin-bottom: 18px; }
/* Apple-style button placement: right-aligned, primary action last (far right), Cancel to its left. */
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; flex-wrap: wrap; }

/* Messages */

.messages { list-style: none; padding: 0; margin: 0 0 20px; }
.messages li { padding: 12px 16px; border-radius: 8px; border: 1px solid; margin-bottom: 8px; }
.messages .success { background: var(--success-light); color: var(--success); border-color: #a7f3d0; }
.messages .error { background: var(--danger-light); color: var(--danger); border-color: #fecaca; }

.warning-box { background: var(--danger-light); border: 1px solid #fecaca; color: #7f1d1d; border-radius: 8px; padding: 14px 16px; margin: 16px 0; }

/* Home */

.hero {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 32px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 28px;
}
.hero-text { padding: 36px 0 36px 36px; }
.hero-text h1 { font-size: 2rem; }
.hero-text .lead { font-size: 1.08rem; color: #334155; }
.hero figure { margin: 0; height: 100%; display: flex; flex-direction: column; }
.hero img { width: 100%; flex: 1; min-height: 280px; object-fit: cover; display: block; }
.hero figcaption { font-size: 0.72rem; color: var(--muted); padding: 6px 12px; background: #f8fafc; }
.hero figcaption a { color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.78rem; font-weight: 700; color: var(--accent); margin: 0 0 8px; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.stat {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  text-decoration: none;
  color: var(--ink);
  border-top: 4px solid var(--accent);
}
.stat:hover { border-color: var(--brand); color: var(--ink); }
.stat .value { display: block; font-size: 2rem; font-weight: 700; color: var(--brand-dark); }
.stat .label { display: block; font-weight: 600; }
.stat .desc { display: block; font-size: 0.88rem; color: var(--muted); }

/* Login */

.login-wrap { display: flex; justify-content: center; align-items: flex-start; padding-top: 24px; }
.login-card { width: 100%; max-width: 420px; }
.login-card .brand { justify-content: center; margin: 0 0 20px; }
.login-card .field { margin-bottom: 16px; }
.login-card .form-actions { margin-top: 8px; }

/* Footer */

.site-footer { background: #0f172a; color: #cbd5e1; padding: 20px 0; font-size: 0.9rem; text-align: center; }

/* Responsive */

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; gap: 0; }
  .hero-text { padding: 28px 24px 8px; }
  .hero figure { order: -1; }
  .hero img { min-height: 0; max-height: 300px; }
}

@media (max-width: 760px) {
  .header-inner { gap: 10px; padding: 10px 0; }
  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
  }
  .nav-toggle .bars, .nav-toggle .bars::before, .nav-toggle .bars::after {
    display: block; width: 18px; height: 2px; background: var(--ink); position: relative; content: "";
  }
  .nav-toggle .bars::before { position: absolute; top: -6px; left: 0; }
  .nav-toggle .bars::after { position: absolute; top: 6px; left: 0; }
  .main-nav, .user-area { display: none; width: 100%; }
  .site-header.nav-open .main-nav, .site-header.nav-open .user-area { display: block; }
  .main-nav ul { flex-direction: column; padding-bottom: 6px; }
  .main-nav a { padding: 12px; }
  .user-area { padding: 10px 12px 6px; border-top: 1px solid var(--line); }
  .site-header.nav-open .user-area { display: flex; justify-content: space-between; }
  .brand-system { display: none; }

  main { padding: 20px 0 36px; }
  .container { padding: 0 16px; }
  h1 { font-size: 1.45rem; }
  .card { padding: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-actions .btn { flex: 1 1 0; justify-content: center; }
  .stats { grid-template-columns: 1fr; }
  dl.details { grid-template-columns: 1fr; }
  dl.details dt { border-bottom: none; padding-bottom: 0; font-size: 0.85rem; }
  dl.details dd { padding-top: 2px; }
  dl.details > :nth-last-child(2) { border-bottom: none; }

  /* Tables become stacked cards on small screens. */
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data tr { border-bottom: 1px solid var(--line); padding: 10px 0; }
  table.data tbody tr:last-child { border-bottom: none; }
  table.data td { border: none; padding: 3px 0; display: flex; gap: 12px; }
  table.data td::before { content: attr(data-label); flex: 0 0 42%; font-size: 0.8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; padding-top: 2px; }
  td.num { width: 100%; }
  table.data tbody tr:hover td { background: none; }
}

@media print {
  .site-header, .site-footer, .actions, .form-actions { display: none; }
  body { background: #fff; }
  .card { box-shadow: none; border: none; padding: 0; }
}

/* Timetable */

.tt-help { margin: -8px 0 16px; font-size: 0.92rem; }
.tt { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 20px; align-items: start; }
.tt .card { margin-bottom: 0; }

.tt-pool { padding: 18px; position: sticky; top: 88px; max-height: calc(100vh - 108px); display: flex; flex-direction: column; }
.tt-pool h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.tt-count { background: var(--brand-light); color: var(--brand-dark); border-radius: 999px; font-size: 0.8rem; padding: 1px 9px; }
.tt-pool-hint { font-size: 0.8rem; margin: 0 0 12px; }
.tt-pool-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 60px; padding: 2px; margin: -2px; }
.tt-empty { display: none; font-size: 0.9rem; text-align: center; padding: 16px 0; }
.tt-pool-empty .tt-empty { display: block; }

.tt-grid-wrap { padding: 0; overflow-x: auto; }
.tt-grid { width: 100%; min-width: 760px; border-collapse: collapse; table-layout: fixed; }
.tt-grid th, .tt-grid td { border-bottom: 1px solid var(--line); border-left: 1px solid var(--line); }
.tt-grid thead th { padding: 10px 8px; background: #f8fafc; text-align: left; font-weight: 600; }
.tt-grid thead th.tt-today { background: var(--brand-light); }
.tt-dayname { display: block; font-size: 0.92rem; color: #0f172a; }
.tt-date { display: block; font-size: 0.75rem; color: var(--muted); font-weight: 500; }
.tt-grid th.tt-time { width: 76px; border-left: none; font-size: 0.78rem; color: var(--muted); font-weight: 600; text-align: right; padding: 8px 10px; vertical-align: top; background: #fff; position: sticky; left: 0; z-index: 1; }
.tt-grid thead th.tt-time { background: #f8fafc; }
.tt-grid tbody tr:last-child td, .tt-grid tbody tr:last-child th { border-bottom: none; }

.tt-cell { height: 72px; padding: 4px; vertical-align: top; transition: background-color 0.12s; }
.tt-cell.tt-today { background: #f7fdfc; }
.tt-cell > .tt-card + .tt-card { margin-top: 4px; }
.tt-is-dragging .tt-cell:hover, .tt-placing .tt-cell:hover { background: #f0fdfa; }
.tt-over, .tt-placing .tt-cell:focus-visible { background: #ccfbf1 !important; box-shadow: inset 0 0 0 2px var(--accent); }
.tt-pool.tt-over { background: #f0fdfa !important; }
.tt-placing .tt-cell, .tt-placing .tt-pool { cursor: copy; }

.tt-card {
  position: relative;
  display: flex;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 7px;
  padding: 7px 26px 7px 4px;
  font-size: 0.8rem;
  line-height: 1.35;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}
.tt-card:hover { border-color: #99f6e4; border-left-color: var(--accent); }
.tt-card-body { min-width: 0; display: flex; flex-direction: column; }
.tt-client { font-weight: 700; text-decoration: none; color: #0f172a; }
.tt-client:hover { color: var(--brand); text-decoration: underline; }
.tt-reason { color: #334155; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tt-meta, .tt-due { color: var(--muted); font-size: 0.74rem; }
.tt-cell .tt-meta, .tt-cell .tt-due { display: none; }
.tt-late-note { display: none; color: #b45309; font-size: 0.72rem; font-weight: 600; }
.tt-cell .tt-card.tt-late { border-left-color: #f59e0b; background: #fffbeb; }
.tt-cell .tt-card.tt-late .tt-late-note { display: block; }
.tt-pool .tt-card.tt-overdue { border-left-color: var(--danger); }
.tt-pool .tt-card.tt-overdue .tt-due { color: var(--danger); font-weight: 600; }

.tt-grip {
  flex: 0 0 12px;
  align-self: stretch;
  touch-action: none;
  cursor: grab;
  border-radius: 4px;
  background-image: radial-gradient(circle, #94a3b8 1.2px, transparent 1.4px);
  background-size: 6px 6px;
  background-position: center;
  opacity: 0.7;
}
.tt-unschedule {
  position: absolute; top: 3px; right: 3px;
  width: 20px; height: 20px; padding: 0;
  border: none; border-radius: 4px; background: none;
  color: var(--muted); font-size: 1rem; line-height: 1; cursor: pointer;
  display: none;
}
.tt-unschedule:hover { background: var(--danger-light); color: var(--danger); }
.tt-cell .tt-unschedule { display: block; }

.tt-selected { outline: 3px solid var(--accent); outline-offset: 1px; box-shadow: 0 4px 14px rgba(13, 148, 136, 0.25); }
.tt-dragging { opacity: 0.35; }
.tt-saving { opacity: 0.6; }
.tt-ghost {
  position: fixed; top: 0; left: 0; z-index: 100; pointer-events: none;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.25); cursor: grabbing; rotate: 1.5deg;
}
.tt-is-dragging, .tt-is-dragging * { cursor: grabbing !important; }

.tt-status {
  position: fixed; left: 50%; bottom: 24px; z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px);
  background: #0f172a; color: #fff; border-radius: 8px; padding: 10px 16px;
  font-size: 0.9rem; box-shadow: var(--shadow);
  transition: opacity 0.2s, transform 0.2s;
}
.tt-status-visible { opacity: 1; transform: translate(-50%, 0); }
.tt-status-error { background: var(--danger); }

@media (max-width: 1000px) {
  .tt { grid-template-columns: minmax(0, 1fr); }
  .tt-pool { position: static; max-height: none; }
  .tt-pool-list { flex-direction: row; overflow-x: auto; overflow-y: visible; padding-bottom: 6px; }
  .tt-pool-list .tt-card { flex: 0 0 210px; }
}
.late-flag { margin-left: 8px; font-size: 0.8rem; font-weight: 600; color: #b45309; background: #fffbeb; border: 1px solid #fde68a; border-radius: 999px; padding: 1px 8px; }
.tt-grid th.tt-time { width: 88px; white-space: nowrap; }
