/*
 * Due Desk page styles (loaded by every page: login, table, settings, admin).
 * Colours use CSS variables in :root so you can theme in one place.
 * Class names match ids/classes in index.html and classes set in app.js (chip, badge, desc, detail).
 */

/* --- Theme tokens (use var(--name) elsewhere) --- */
:root {
  color-scheme: light;
  --bg: #f7f7f9;
  --panel: #ffffff;
  --text: #1c1c1e;
  --muted: #6b6b73;
  --border: #dcdce1;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --mark: #fde68a;
  --new: #16a34a;
  --soon: #d97706;
  --over: #dc2626;
  --row-hover: #f0f4ff;
}

* { box-sizing: border-box; }

/* Base font size for the whole page (buttons/inputs use font: inherit). */
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 12px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* --- Header: title, Refresh, last-refreshed status --- */
.topbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

/* Row one: title on the left, email and links on the right. Row two: child chips, status, Refresh. */
.topbar-main { display: flex; align-items: center; gap: 16px; }
.topbar-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.topbar-sub .status { flex: 1 1 auto; }
.user-email { color: var(--muted); }

.topbar h1 { margin: 0; font-size: 24px; }
.status { color: var(--muted); }
.status.error { color: var(--over); }

/* --- Search, Reset, filter chips --- */
.controls { padding: 12px 20px 4px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 10px; }

button, select, input {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
}

/* Every button: outlined, blue text, no fill, square corners. (Chips, link buttons and Delete are set below.) */
button { cursor: pointer; background: transparent; color: var(--accent); border-color: var(--accent); border-radius: 0; }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { display: inline-flex; align-items: center; gap: 8px; }
button .icon { width: 14px; height: 14px; flex: none; }
button .spinner:not([hidden]) + .icon { display: none; }

.search { position: relative; flex: 1 1 320px; max-width: 520px; }
.search input { width: 100%; padding-right: 30px; }
.clear { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: 0; background: none; padding: 2px 8px; font-size: 18px; color: var(--muted); }
.matches { color: var(--muted); min-width: 90px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border-radius: 999px; padding: 4px 12px; background: var(--panel); color: var(--text); border-color: var(--border); }
.chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chips + .chips { margin-left: 16px; }

/* --- Data table (rows are built in app.js) --- */
.table-wrap { margin: 0 20px; overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }

/*
 * table-layout: fixed keeps column widths stable when a row expands (see tr.detail).
 * Without it, a long description in the detail row can reflow other rows and change their height.
 */
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 8px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); min-width: 0; }

/* Column order matches COLUMNS in app.js (9 columns). Adjust widths if you add/remove columns. */
#table th:nth-child(1), #table td:nth-child(1) { width: 4rem; }       /* date */
#table th:nth-child(2), #table td:nth-child(2) { width: 5rem; }     /* type */
#table th:nth-child(3), #table td:nth-child(3) { width: 6rem; }     /* category */
#table th:nth-child(4), #table td:nth-child(4) { width: 10%; }         /* subject */
#table th:nth-child(5), #table td:nth-child(5) { width: 12%; }        /* title */
#table th:nth-child(6), #table td:nth-child(6) { width: 4rem; }       /* submission_end_date (Due) */
#table th:nth-child(7), #table td:nth-child(7) { width: 9%; }         /* teacher */
#table th:nth-child(8), #table td:nth-child(8) { width: 32%; }        /* description */
#table th:nth-child(9), #table td:nth-child(9) { width: 14%; }        /* link */

th { position: sticky; top: 0; background: var(--panel); cursor: pointer; user-select: none; white-space: nowrap; }
th .arrow { color: var(--accent); margin-left: 4px; }
tbody tr.data { cursor: pointer; }
tbody tr.data:hover { background: var(--row-hover); }
/* Shorter data rows: one line per cell; click the row for the full description. */
tbody tr.data td {
  padding: 5px 8px;
  vertical-align: middle;
}
td.nowrap { white-space: nowrap; }
td.desc { color: var(--muted); }

tbody tr.data td.desc,
tbody tr.data td:nth-child(5) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Link column: one line per row. The text is also cut to 30 characters in table.js; the full name is the tooltip. */
tbody tr.data td:nth-child(9) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Full description row inserted below the clicked tr.data (colspan in app.js). */
tr.detail td {
  background: var(--bg);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* Search hit highlighting (app.js wraps matches in <mark>). */
mark { background: var(--mark); color: inherit; border-radius: 2px; }

.badge { display: inline-block; padding: 0 6px; margin-left: 6px; border-radius: 999px; font-size: 11px; color: #fff; background: var(--new); }
.badge.badge-before { margin-left: 0; margin-right: 6px; }  /* pill placed before the text (Type column) */
.badge.soon { background: var(--soon); }
.badge.overdue { background: var(--over); }

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

/* --- Footer pager --- */
.pager { display: flex; align-items: center; gap: 12px; padding: 12px 20px 24px; }
.showing { color: var(--muted); margin-left: auto; }

.spinner { width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
.spinner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================================
 * Added for accounts, messages and the other pages
 * ========================================================================== */

/* An element with the hidden attribute must stay hidden even when a class gives it a display value. */
[hidden] { display: none !important; }

/* --- Top bar links (Settings, Admin, Log out) --- */
.nav { margin-left: auto; display: flex; align-items: center; gap: 14px; }
/* Links (including the table's Link column and attachments) are blue and never underlined. */
a { color: var(--accent); text-decoration: none; }
a:hover, button.link:hover { color: #1d4ed8; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: none; cursor: pointer; }
a.button { display: inline-block; padding: 6px 12px; border-radius: 0; border: 1px solid var(--accent); text-decoration: none; background: transparent; color: var(--accent); }
a.button.primary { background: transparent; color: var(--accent); border-color: var(--accent); }

/* --- Banners: yellow = a problem that will fix itself, red = needs you or do not trust the list --- */
.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 10px 20px 0; padding: 10px 14px; border-radius: 8px; border: 1px solid; }
.banner.yellow { background: #fef9c3; border-color: #facc15; color: #713f12; }
.banner.red { background: #fee2e2; border-color: #f87171; color: #7f1d1d; }
.banner .banner-action { font-weight: 600; }
.banner button.link { color: inherit; }
.freshness { margin: 8px 20px 0; color: var(--muted); }

/* --- Friendly panels: first use, progress, empty states --- */
.first-use { margin: 20px; padding: 28px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; max-width: 640px; }
.first-use h2 { margin: 0 0 8px; font-size: 18px; }
.first-use p { margin: 0 0 14px; font-size: 13px; }
.small { color: var(--muted); font-size: 12px !important; }
ul.progress { list-style: none; padding: 0; margin: 0 0 14px; font-size: 13px; }
ul.progress li { padding: 3px 0; color: var(--muted); }
ul.progress li.done { color: var(--new); }
ul.progress li.running { color: var(--text); font-weight: 600; }
ul.progress li.failed { color: var(--over); }

/* --- Small form messages --- */
.message { margin: 10px 0 0; padding: 8px 10px; border-radius: 6px; background: var(--bg); }
.message.error { background: #fee2e2; color: #7f1d1d; }
.message.ok { background: #dcfce7; color: #14532d; }

/* --- Login / settings / admin / text pages --- */
.page { max-width: 640px; margin: 0 auto; padding: 32px 20px 60px; }
.page.wide { max-width: 1200px; }
.page h1 { font-size: 22px; margin: 0 0 4px; }
.page h2 { font-size: 15px; margin: 0 0 10px; }
.page .lead { color: var(--muted); margin: 0 0 20px; font-size: 13px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 18px; margin-bottom: 16px; }
.card p { margin: 0 0 10px; }
form.stack { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
form.stack label.inline { flex-direction: row; align-items: center; }
input[type=checkbox] { width: auto !important; }
form.stack label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
form.stack label span.hint { font-weight: 400; color: var(--muted); }
form.stack input, form.stack select { width: 100%; max-width: 480px; }

/* Password field with an always-visible show/hide button (added by common.js to every password input). */
.pw-wrap { position: relative; display: flex; width: 100%; max-width: 480px; }
.inline .pw-wrap { width: auto; }
.pw-wrap input { width: 100%; max-width: none; padding-right: 36px; }
.pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); display: flex; align-items: center; border: 0; padding: 4px; color: var(--muted); }
.pw-toggle:hover { color: var(--accent); }
.pw-toggle svg { width: 16px; height: 16px; }
input[type=password]::-ms-reveal, input[type=password]::-ms-clear { display: none; }
.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.inline input { width: auto; }
form.stack div > span.message { display: inline-block; margin: 0 0 0 10px; }
form.stack div > span.message[hidden] { display: none; }

/* Family tile */
.member-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.family-note { margin-top: 12px; }
.invite-form { margin-top: 16px; }
.links { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 14px; }
.danger { color: var(--over); border-color: var(--over); }
.back { display: inline-block; margin-bottom: 14px; }
.back + button.link { margin-left: 16px; }
dialog.feedback { border: 1px solid var(--border); border-radius: 8px; padding: 18px; width: min(460px, 92vw); background: var(--panel); color: inherit; }
dialog.feedback::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog.feedback textarea { width: 100%; min-height: 120px; box-sizing: border-box; }
dialog.feedback .count { text-align: right; margin: 2px 0 0; }
dialog.feedback .actions { display: flex; gap: 10px; margin-top: 12px; }
table.plain { table-layout: auto; }
/* Admin Users table: tight cells, no wrapping, so each user fits on one row. */
table.compact th, table.compact td { padding: 6px 8px; white-space: nowrap; font-size: 13px; }
table.compact td.inline { flex-wrap: nowrap; }
table.plain th { position: static; cursor: default; }
table.plain td { vertical-align: middle; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; word-break: break-all; }

/* Feedback screenshots: small thumbnails with a remove button */
.pictures { display: flex; flex-wrap: wrap; gap: 8px; }
.pictures:empty { display: none; }
.picture { position: relative; display: inline-block; }
.picture img { display: block; height: 64px; max-width: 120px; object-fit: cover; border: 1px solid var(--border); }
.picture .link { position: absolute; top: 0; right: 0; padding: 0 6px; background: var(--panel); color: var(--over); line-height: 1.4; }
