/* ==========================================================================
   APOC IT Evidencija — stylesheet
   --------------------------------------------------------------------------
   Organisation:
     1. Design tokens (light)        6. Lists and records
     2. Design tokens (dark)         7. Tables
     3. Base elements + focus        8. Components
     4. Layout and chrome            9. Feature areas
     5. Forms and buttons           10. Responsive + print

   Colours are ONLY ever referenced through a custom property. If you find
   yourself typing a hex value outside sections 1-2, add a token instead.
   ========================================================================== */

/* ========================================================================== */
/* 1. Design tokens (light)                                                   */
/* ========================================================================== */

:root {
  /* surfaces */
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-sunken: #f6f8f9;
  --surface-raised: #f1f7f8;
  --border: #dce5e9;
  --border-subtle: #e7edef;
  --border-strong: #bdcdd4;

  /* text */
  --text: #243040;
  --text-muted: #667b85;
  --text-faint: #72828c;
  --text-on-brand: #ffffff;
  --text-on-nav: #e4f3f5;

  /* brand */
  --brand: #12647a;
  --brand-hover: #0d4c5d;
  --brand-subtle: #e9f1f3;
  --brand-subtle-text: #164356;
  --link: #14637b;
  --nav-bg: #132b38;
  --nav-menu-bg: #1b3c4c;
  --nav-menu-hover: #2c5264;

  /* state */
  --ok: #16543e;
  --ok-subtle: #dff3eb;
  --ok-border: #a9d5c2;
  --danger: #a52b2b;
  --danger-hover: #7d2020;
  --accent-subtle: #e2f1f4;
  --accent-subtle-text: #18536a;

  /* geometry */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 5px;
  --tap: 44px;              /* minimum touch target — never go below this */
  --content-max: 1180px;
  --shadow-card: 0 2px 9px #2233440a;
  --shadow-menu: 0 8px 22px #10212b45;
  --shadow-toolbar: 0 3px 12px #132b3814;

  /* typography */
  font: 16px/1.5 system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* ========================================================================== */
/* 2. Design tokens (dark)                                                    */
/* -------------------------------------------------------------------------- */
/* Declared twice on purpose: once for the OS preference (unless the user has  */
/* explicitly chosen light), once for an explicit [data-theme="dark"] toggle.  */
/* ========================================================================== */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121a20;
    --surface: #1a252d;
    --surface-sunken: #141d24;
    --surface-raised: #1f2f38;
    --border: #2b3a44;
    --border-subtle: #243139;
    --border-strong: #3c505c;

    --text: #dce6ec;
    --text-muted: #94a8b2;
    --text-faint: #8396a0;
    --text-on-brand: #07171d;
    --text-on-nav: #dceef2;

    --brand: #4db3cf;
    --brand-hover: #6ec6de;
    --brand-subtle: #1d3b45;
    --brand-subtle-text: #a9dbe8;
    --link: #68c0d8;
    --nav-bg: #0d1a22;
    --nav-menu-bg: #16303c;
    --nav-menu-hover: #224a5b;

    --ok: #7fd9b0;
    --ok-subtle: #16332a;
    --ok-border: #2f6a54;
    --danger: #f08a8a;
    --danger-hover: #f4a5a5;
    --accent-subtle: #1d3b45;
    --accent-subtle-text: #a9dbe8;

    --shadow-card: 0 2px 9px #0006;
    --shadow-menu: 0 8px 22px #0008;
    --shadow-toolbar: 0 3px 12px #0007;
  }
}

:root[data-theme="dark"] {
  --bg: #121a20;
  --surface: #1a252d;
  --surface-sunken: #141d24;
  --surface-raised: #1f2f38;
  --border: #2b3a44;
  --border-subtle: #243139;
  --border-strong: #3c505c;

  --text: #dce6ec;
  --text-muted: #94a8b2;
  --text-faint: #8396a0;
  --text-on-brand: #07171d;
  --text-on-nav: #dceef2;

  --brand: #4db3cf;
  --brand-hover: #6ec6de;
  --brand-subtle: #1d3b45;
  --brand-subtle-text: #a9dbe8;
  --link: #68c0d8;
  --nav-bg: #0d1a22;
  --nav-menu-bg: #16303c;
  --nav-menu-hover: #224a5b;

  --ok: #7fd9b0;
  --ok-subtle: #16332a;
  --ok-border: #2f6a54;
  --danger: #f08a8a;
  --danger-hover: #f4a5a5;
  --accent-subtle: #1d3b45;
  --accent-subtle-text: #a9dbe8;

  --shadow-card: 0 2px 9px #0006;
  --shadow-menu: 0 8px 22px #0008;
  --shadow-toolbar: 0 3px 12px #0007;
}

/* ========================================================================== */
/* 3. Base elements + focus                                                   */
/* ========================================================================== */

* { box-sizing: border-box }

body {
  margin: 0;
  background: var(--bg);          /* explicit, so dark mode cannot fall through */
  color: var(--text);
}

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

h1 { font-size: 2rem; line-height: 1.2 }
h2 { font-size: 1.2rem; margin: 0 0 1rem }

/* Focus. The previous stylesheet had NO focus rules at all, and buttons set
   border:0 over a custom background, so keyboard users had nothing to follow. */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 2px;
}
/* Inside the dark header the brand teal has too little contrast to read as a
   ring, so use the on-nav text colour there instead. */
header :focus-visible,
.nav-menu > div :focus-visible { outline-color: var(--text-on-nav) }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Skip link — visible only once focused. */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--surface);
  color: var(--text);
  padding: .7rem 1rem;
  border-radius: 0 0 var(--radius-sm) 0;
  font-weight: 650;
}
.skip-link:focus { left: 0 }

/* ========================================================================== */
/* 4. Layout and chrome                                                       */
/* ========================================================================== */

header {
  background: var(--nav-bg);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: .8rem max(1rem, calc((100vw - var(--content-max)) / 2));
  flex-wrap: wrap;
}

.brand {
  font-weight: 800;
  font-size: 1.25rem;
  color: #fff;
  white-space: nowrap;
}
.brand span { font-weight: 400 }

nav { display: flex; gap: 1rem; flex: 1; flex-wrap: wrap }
nav a {
  color: var(--text-on-nav);
  /* Touch target: these were ~24px tall. */
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 .15rem;
}
/* "You are here" — the 11-item nav previously gave no active signal at all. */
nav a[aria-current="page"] {
  font-weight: 700;
  box-shadow: inset 0 -2px 0 var(--text-on-nav);
}

header form { margin: 0 }

.account-link {
  color: var(--text-on-nav);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
}

main {
  max-width: var(--content-max);
  margin: auto;
  padding: 1.4rem 1rem 4rem;
}

.heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 1.2rem;
}
.heading h1, .heading h2 { margin: 0 }

.eyebrow {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.3rem;
  margin: 0 0 1rem;
  box-shadow: var(--shadow-card);
}

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem }
.narrow { max-width: 620px }

/* ========================================================================== */
/* 5. Forms and buttons                                                       */
/* ========================================================================== */

button, .button {
  background: var(--brand);
  color: var(--text-on-brand);
  border: 0;
  border-radius: var(--radius-sm);
  padding: .72rem 1rem;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}
button:hover, .button:hover { background: var(--brand-hover); text-decoration: none }

.secondary, .ghost { background: var(--brand-subtle); color: var(--brand-subtle-text) }
.secondary:hover, .ghost:hover { background: var(--border); color: var(--brand-subtle-text) }
/* .ghost was ~30px tall — below the 44px floor. Padding reduced but min-height
   keeps the target legal. */
.ghost { padding: .4rem .7rem }

.danger { background: var(--danger); color: #fff }
.danger:hover { background: var(--danger-hover) }
.danger-link { color: var(--danger); font-weight: 650 }

input, select, textarea {
  font: inherit;
  color: inherit;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  padding: .55rem;
  width: 100%;
  background: var(--surface);
  min-height: var(--tap);
}
textarea { min-height: 6rem }
input[type=checkbox] { width: auto; min-height: 0; min-width: 1.15rem; height: 1.15rem }
input[type=file] { margin: 0 0 1rem }

label { display: block; font-weight: 600 }
form p { margin: .75rem 0 }
form p label { display: block; margin-bottom: .25rem }

.form-card { max-width: 760px }
.form-card button { margin-top: 1rem }

.helptext { display: block; color: var(--text-muted); font-size: .83rem }
.errorlist { color: var(--danger) }
.field-errors { display: block }

.login { max-width: 400px; margin: 5vh auto }

.filters { display: flex; align-items: end; gap: .7rem; flex-wrap: wrap }
.filters label { min-width: 145px }
.filters button { height: var(--tap) }

/* ========================================================================== */
/* 6. Lists and records                                                       */
/* ========================================================================== */

.records { list-style: none; padding: 0; margin: 0 }
.records li { border-top: 1px solid var(--border-subtle); padding: .65rem 0 }
.records li:first-child { border-top: 0 }
.records a { display: block; min-height: var(--tap); padding: .35rem 0 }
.records small, td small { display: block; color: var(--text-muted) }

.state { background: var(--surface-raised); padding: .6rem .8rem; border-radius: var(--radius-sm) }
.state.active { background: var(--ok-subtle); color: var(--ok) }

.text-link { display: inline-block; margin: .8rem 0 }

.metric strong { font-size: 2.6rem; display: block; line-height: 1 }
.metric span { color: var(--text-muted) }

.stats { margin-top: 1rem }
.stats p, .properties p {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-top: 1px solid var(--border-subtle);
  padding: .45rem 0;
  margin: 0;
}

.notes {
  white-space: pre-wrap;
  font: inherit;
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
  padding: 1rem;
  min-height: 5rem;
}

/* ========================================================================== */
/* 7. Tables                                                                  */
/* ========================================================================== */

.table-wrap { overflow-x: auto }

table { border-collapse: collapse; width: 100%; min-width: 640px }
th, td {
  text-align: left;
  padding: .7rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th { font-size: .8rem; text-transform: uppercase; color: var(--text-muted) }
.total { font-weight: 700; background: var(--surface-raised) }

/* Sticky header for long tables. */
.table-wrap thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

/* --------------------------------------------------------------------------
   Opt-in responsive table: add class="cards" to a <table> and data-label="…"
   to each <td>, and on a phone the table re-renders as one card per row
   instead of forcing a 640px horizontal scroll.

   Opt-in rather than global so the 13 existing table templates keep working
   untouched and can be converted one at a time.
   -------------------------------------------------------------------------- */
@media (max-width: 639px) {
  table.cards { min-width: 0; display: block }
  table.cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%) }
  table.cards tbody, table.cards tr, table.cards td { display: block; width: auto }
  table.cards tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .5rem .8rem;
    margin: 0 0 .6rem;
  }
  table.cards td { border: 0; padding: .25rem 0; display: flex; gap: .8rem; justify-content: space-between }
  table.cards td::before {
    content: attr(data-label);
    font-size: .8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    flex: 0 0 auto;
  }
  table.cards td[data-label=""]::before { content: none }
  table.cards tr.total { background: var(--surface-raised) }
  .table-wrap:has(table.cards) { overflow-x: visible }
}

/* ========================================================================== */
/* 8. Components                                                              */
/* ========================================================================== */

.message {
  background: var(--ok-subtle);
  border: 1px solid var(--ok-border);
  color: var(--text);
  padding: .7rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
}

.pill {
  display: inline-block;
  background: var(--accent-subtle);
  color: var(--accent-subtle-text);
  border-radius: 99px;
  padding: .2rem .6rem;
  font-size: .8rem;
}

.autosave-status { display: block; min-height: 1.2rem; color: var(--text-muted); margin: .35rem 0 }

.muted { color: var(--text-faint); font-size: .9rem }

/* Pagination -------------------------------------------------------------- */
.pagination {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin: 1rem 0 0;
}
.pagination a, .pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.pagination a:hover { background: var(--brand-subtle); text-decoration: none }
.pagination [aria-current="page"] {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--text-on-brand);
  font-weight: 700;
}
.pagination .page-info { border: 0; background: none; color: var(--text-muted); font-size: .9rem }

/* Markdown ---------------------------------------------------------------- */
.markdown { line-height: 1.6; overflow-wrap: anywhere }
.markdown pre { overflow: auto; background: var(--surface-sunken); padding: 1rem; border-radius: var(--radius-sm) }
.markdown table { min-width: 0 }
.markdown h1, .markdown h2, .markdown h3 { margin-top: 1.2em }

/* Materials --------------------------------------------------------------- */
.materials-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin: 1rem 0;
}
.materials-fieldset legend { font-weight: 700; padding: 0 .35rem }
.material-row { border-top: 1px solid var(--border-subtle); padding: .8rem 0 }
.material-row:first-of-type { border-top: 0 }
.material-row p { margin: .45rem 0 }

/* Admin dataset switcher -------------------------------------------------- */
.admin-datasets { display: flex; gap: .5rem; flex-wrap: wrap; margin: 1rem 0 }
.admin-datasets a {
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: .35rem .7rem;
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
}
.admin-datasets a.active { background: var(--brand); color: var(--text-on-brand); border-color: var(--brand) }

/* Nav dropdown ------------------------------------------------------------ */
.nav-menu { position: relative }
.nav-menu summary {
  cursor: pointer;
  list-style: none;
  color: var(--text-on-nav);
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
}
.nav-menu summary::-webkit-details-marker { display: none }
.nav-menu > div {
  position: absolute;
  z-index: 20;
  top: 2.6rem;
  left: 0;
  min-width: 175px;
  background: var(--nav-menu-bg);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-menu);
  padding: .4rem;
  display: grid;
  gap: 0;
}
.nav-menu > div a {
  display: flex;
  align-items: center;
  min-height: var(--tap);
  padding: .45rem .6rem;
  border-radius: var(--radius-xs);
  color: var(--text-on-nav);
}
.nav-menu > div a:hover { background: var(--nav-menu-hover); text-decoration: none }

/* ========================================================================== */
/* 9. Feature areas                                                           */
/* ========================================================================== */

/* Availability calendar --------------------------------------------------- */
.availability-head,
.availability-row {
  display: grid;
  grid-template-columns: 150px repeat(7, minmax(100px, 1fr));
  gap: 8px;
}
.availability-grid { overflow-x: auto }
.availability-head { font-size: .85rem; padding-bottom: 12px }
.availability-row { border-top: 1px solid var(--border); padding: 14px 0 }
.availability-cell {
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.day-status { font-size: .85rem; font-weight: 600 }
.time-block {
  background: var(--accent-subtle);
  color: var(--accent-subtle-text);
  border-radius: var(--radius-xs);
  padding: 4px;
  font-size: .85rem;
  white-space: nowrap;
}
.availability-cell small { color: var(--text-muted) }
.mobile-day { display: none }
.time-block-form {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin: 16px 0;
}
.time-block-form legend { font-weight: 600 }

/* Team day workspace ------------------------------------------------------ */
.team-toolbar { position: sticky; top: 0; z-index: 2; box-shadow: var(--shadow-toolbar) }
.team-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin: .9rem 0 }
.team-employee > summary {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  cursor: pointer;
  padding: .35rem 0;
  min-height: var(--tap);
  align-items: center;
}
.team-summary { color: var(--text-muted); font-size: .9rem }
.team-employee[open] > summary { border-bottom: 1px solid var(--border); padding-bottom: 1rem }
.team-record { display: block; text-align: left; width: 100%; margin: .4rem 0 }
.team-record:hover { color: var(--text-on-brand) }
.team-edit-panel {
  background: var(--surface-sunken);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 1.2rem;
  margin-top: 1rem;
}
.team-edit-panel .heading h2 { font-size: 1.1rem }
.team-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem }
.team-fields [data-field=notes],
.team-fields [data-field=materials],
.team-fields [data-field=description] { grid-column: 1 / -1 }
.team-fields small { display: block; color: var(--text-muted); margin-top: .3rem }
.team-status { min-height: 1.5rem; color: var(--brand) }
.team-checks { display: flex; flex-wrap: wrap; gap: 1rem; margin: 1rem 0 }
.team-checks input,
.shared-row input,
#shared-hours input[type=checkbox] { width: auto }
.shared-row { display: block; margin: .6rem 0 }
.team-editor textarea { min-height: 100px }
.team-editor details { margin: 1rem 0 }

/* ========================================================================== */
/* 10. Responsive + print                                                     */
/* -------------------------------------------------------------------------- */
/* Three breakpoints. The previous stylesheet had exactly one (700px), which   */
/* is why tablet layouts never existed.                                        */
/* ========================================================================== */

/* --- Tablet: 640-1024px --------------------------------------------------- */
@media (max-width: 1024px) {
  .team-fields { grid-template-columns: repeat(2, minmax(0, 1fr)) }
  .availability-head,
  .availability-row { grid-template-columns: 120px repeat(7, minmax(80px, 1fr)) }
}

/* --- Phone: below 640px --------------------------------------------------- */
@media (max-width: 639px) {
  header { gap: .6rem; padding: 1rem }
  /* Keep the account link and Log out together on the first row, so the nav
     strip below holds navigation only. */
  .account-link { order: 1; margin-left: auto }
  header form { order: 2 }
  nav {
    order: 3;
    width: 100%;
    overflow: auto;
    flex-wrap: nowrap;
    gap: .8rem;
    font-size: .9rem;
    /* Momentum scroll + a hint that there is more to the right. */
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }
  nav a { scroll-snap-align: start }
  .nav-menu > div { left: auto; right: 0 }

  .grid { grid-template-columns: 1fr }
  .heading { align-items: start; flex-wrap: wrap }
  .heading h1 { font-size: 1.65rem }
  .card { padding: 1rem }
  .filters > * { flex: 1 1 140px }
  .metric strong { font-size: 2.2rem }

  .team-fields { grid-template-columns: 1fr }
  .team-employee > summary { display: block }
  .team-summary { display: block; margin-top: .5rem }
  .team-toolbar { position: static }
  .team-edit-panel { padding: .75rem }

  .availability-head { display: none }
  .availability-row { grid-template-columns: 1fr 1fr }
  .availability-row > div:first-child { grid-column: 1 / -1 }
  .mobile-day { display: block }
  .availability-grid { overflow: visible }
}

/* --- Print ---------------------------------------------------------------- */
@media print {
  header, .no-print, .pagination, .skip-link { display: none !important }
  body { background: #fff; color: #000 }
  main { max-width: none }
  .card { box-shadow: none; border: 0; padding: 0 }
  table { min-width: 0 }
  a { color: #000; text-decoration: underline }
}

/* ========================================================================== */
/* Utilities                                                                  */
/* ========================================================================== */

[hidden] { display: none !important }

/* Visually hidden but available to screen readers. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
