/* Production journal – a single stylesheet, no framework. Colours follow the Sprężyny Książek brand. */
:root {
  --red: #b80000;
  --red-dark: #8f0000;
  --graphite: #2b2b2b;
  --text: #222;
  --muted: #6b6b6b;
  --line: #e3e3e3;
  --bg: #f4f4f5;
  --surface: #fff;
  --ok: #1f7a3a;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font: 16px/1.5 var(--font); color: var(--text); background: var(--bg); }
h1, h2 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
a { color: var(--red); }
a:hover { color: var(--red-dark); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--red) 45%, transparent); outline-offset: 2px; }
.muted { color: var(--muted); }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem clamp(1rem, 3vw, 2rem); background: var(--graphite); color: #fff;
}
.brand {
  display: flex; align-items: center; gap: .8rem; padding: .25rem .8rem .25rem .5rem; margin-left: -.5rem;
  border-radius: 8px; color: #fff; text-decoration: none; font-weight: 600; transition: background .15s;
}
.brand:hover, .brand:focus-visible { background: #444; color: #fff; }
.brand img { height: 36px; width: auto; }
.brand span { padding-left: .8rem; border-left: 1px solid #555; }
.topbar-spacer { flex: 1; }
.usermenu summary {
  color: #ddd; text-decoration: none; padding: .45rem .75rem; border-radius: 8px; cursor: pointer;
}
.usermenu summary:hover { background: #3a3a3a; color: #fff; }

/* Left menu of the current module */
.shell { display: grid; grid-template-columns: 14rem minmax(0, 1fr); align-items: start; }
.sidenav {
  position: sticky; top: 3.7rem; display: grid; gap: .15rem; align-content: start;
  margin: 1rem 0 0 clamp(.5rem, 2vw, 1.5rem); padding: .6rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.sidenav-title { margin: .3rem .7rem .5rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.sidenav a { padding: .5rem .7rem; border-radius: 7px; color: var(--text); text-decoration: none; font-weight: 500; }
.sidenav a:hover { background: var(--bg); }
.sidenav a[aria-current] { background: #fbeaea; color: var(--red-dark); font-weight: 600; }
.usermenu { position: relative; }
.usermenu summary { list-style: none; }
.usermenu summary::after { content: " ▾"; font-size: .8em; }
.usermenu > div {
  position: absolute; right: 0; top: calc(100% + .4rem); min-width: 12rem; padding: .4rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / .12);
}
.usermenu > div a, .usermenu > div button {
  display: block; width: 100%; text-align: left; padding: .5rem .7rem; border: 0; border-radius: 6px;
  background: none; color: var(--text); font: inherit; text-decoration: none; cursor: pointer;
}
.usermenu > div a:hover, .usermenu > div button:hover { background: var(--bg); }

/* Content */
.page { width: 100%; min-width: 0; max-width: 1200px; margin: 0 auto; padding: clamp(1rem, 3vw, 2rem); }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; }
.page-head h1 { margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(1rem, 3vw, 1.8rem); }
.narrow { max-width: 28rem; margin: 0 auto; }

/* Messages */
.alert { padding: .7rem 1rem; border-radius: 8px; margin: 0 0 1rem; background: #eef6f0; color: var(--ok); }
.alert-error, .alert-warning { background: #fbeaea; color: var(--red-dark); }

/* Forms and buttons */
.form { display: grid; gap: 1rem; }
.form label { display: grid; gap: .35rem; font-weight: 600; font-size: .95rem; }
input[type=text], input[type=password], input[type=search], input:not([type]), select, textarea {
  width: 100%; padding: .65rem .8rem; font: inherit; font-weight: 400; color: var(--text);
  background: var(--surface); border: 1px solid #cfcfcf; border-radius: 8px;
}
input:focus, select:focus, textarea:focus { border-color: var(--red); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 18%, transparent); }
.error { color: var(--red-dark); font-weight: 400; }
.form .helptext, .form ul { font-weight: 400; font-size: .85rem; color: var(--muted); margin: 0; padding-left: 1.1rem; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1.1rem; border: 1px solid #cfcfcf; border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: #aaa; color: var(--text); }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); border-color: var(--red-dark); color: #fff; }

/* Filters */
.filters { display: flex; gap: .6rem; align-items: center; }
.filters input[type=search] { width: 22rem; max-width: 100%; }
.segmented { display: inline-flex; padding: 3px; background: #e6e6e8; border-radius: 9px; }
.segmented a { padding: .4rem .85rem; border-radius: 7px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .92rem; }
.segmented a[aria-current] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .1); }

/* Table */
.table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: .75rem 1rem; text-align: left; border-bottom: 1px solid var(--line); }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafafa; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafafa; }
.badge { display: inline-block; padding: .15rem .6rem; border-radius: 99px; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.badge-live { background: #fbeaea; color: var(--red); }
.badge-done { background: #ececee; color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1.2rem; }

/* Empty state */
.empty { text-align: center; padding: clamp(1.5rem, 6vw, 4rem) 1rem; }
.empty img { max-width: 100%; height: auto; margin-bottom: 1.2rem; }
.empty p { max-width: 32rem; margin: 0 auto 1.2rem; }

/* Login: form on the dark left part of the background */
body.login {
  min-height: 100vh; display: flex; align-items: center;
  background: #1f1f1f url("../img/logowanie-tlo.webp") right center / cover no-repeat;
}
/* Login uses muted steel tones instead of the red accent, to blend with the photo. */
.login-panel {
  --steel: #c9ced5;
  width: min(26rem, 100%); margin-left: clamp(1rem, 8vw, 8rem); padding: 2rem; color: #e6e8eb;
}
.login-panel h1 { font-size: 1.3rem; font-weight: 500; color: #d9dde2; margin: 1.4rem 0 1.6rem; letter-spacing: .02em; }
.login-logo { width: 240px; max-width: 100%; height: auto; }
.login-panel .form label { color: #aeb4bc; font-weight: 500; }
.login-panel input { background: rgb(255 255 255 / .05); border-color: #44484e; color: #f2f3f5; }
.login-panel input:focus { background: rgb(255 255 255 / .08); border-color: var(--steel); box-shadow: 0 0 0 3px rgb(201 206 213 / .18); }
.login-panel :focus-visible { outline-color: rgb(201 206 213 / .5); }
.login-panel .btn-primary { width: 100%; padding: .75rem; margin-top: .4rem; background: var(--steel); border-color: var(--steel); color: #1d2025; }
.login-panel .btn-primary:hover { background: #e3e6ea; border-color: #e3e6ea; color: #1d2025; }
.login-panel .muted { color: #8a9099; font-size: .9rem; margin-top: 1.4rem; }
.login-panel .alert-error { background: rgb(255 255 255 / .08); color: #f0c9c9; }

/* Phone / narrow screen: table rows become cards */
@media (max-width: 720px) {
  .brand span { display: none; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidenav { position: static; display: flex; overflow-x: auto; margin: .6rem .6rem 0; }
  .sidenav-title { display: none; }
  .sidenav a { white-space: nowrap; }
  .filters { flex-wrap: wrap; }
  .filters, .segmented, .filters input[type=search] { width: 100%; }
  .segmented a { flex: 1; text-align: center; }
  .table, .table tbody, .table tr, .table td { display: block; border: 0; }
  .table { background: none; }
  .table thead { display: none; }
  .table tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .7rem; padding: .4rem 0; }
  .table td { display: flex; justify-content: space-between; gap: 1rem; padding: .35rem 1rem; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; }
  body.login { background-position: 70% center; }
  .login-panel { margin: 0 auto; background: rgb(20 20 20 / .75); border-radius: var(--radius); }
}

/* Journal pages: spring cards, forms, characteristics editor, details */
.alert-info { background: #eef2f7; color: #3b4a5e; }
.alert ul { margin: 0; padding-left: 1.1rem; }
.section-title { margin: 1.6rem 0 .7rem; }
.hint { font-weight: 400; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.spring-card {
  display: grid; justify-items: center; gap: .6rem; padding: 1.2rem 1rem; text-align: center; font-weight: 600;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); text-decoration: none;
}
.spring-card:hover { border-color: #aaa; box-shadow: 0 4px 14px rgb(0 0 0 / .08); color: var(--text); }
.spring-card img, .spring-card-blank { width: 96px; height: 96px; object-fit: contain; }
.spring-card-blank { border: 2px dashed var(--line); border-radius: 50%; }
.form-section { margin-bottom: 1rem; }
.form-section h2 { margin-bottom: .8rem; }
textarea { resize: vertical; max-height: 12rem; } /* never wider than its cell */
/* Same four columns in every section, so fields line up between "Zlecenie" and "Sprężyna". */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 1rem; align-items: start; }
@media (min-width: 1000px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.journal-form label { display: grid; gap: .35rem; align-content: start; font-weight: 600; font-size: .95rem; }
.form-section .grid input, .form-section .grid select { min-height: 2.75rem; }
.journal-form input[type=date], .journal-form input[type=number], .journal-form textarea { width: 100%; padding: .65rem .8rem; font: inherit; font-weight: 400; border: 1px solid #cfcfcf; border-radius: 8px; }
.journal-form select { width: 100%; padding: .6rem .5rem; font: inherit; font-weight: 400; border: 1px solid #cfcfcf; border-radius: 8px; background: var(--surface); }
.table-scroll { overflow-x: auto; margin-bottom: .8rem; }
.editor { width: 100%; border-collapse: collapse; min-width: 62rem; }
.editor th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .3rem .3rem; }
.editor td { padding: .25rem .3rem; vertical-align: middle; }
.editor input[type=text], .editor input[type=number], .editor select { padding: .45rem .5rem; font-size: .92rem; }
.editor .narrow-input { min-width: 4.5rem; }
.editor .center { text-align: center; }
.editor .center input { width: 1.2rem; height: 1.2rem; accent-color: var(--red); }
.editor tr:not([data-type=number]) .tol { visibility: hidden; }
.editor .tol-group { text-align: center; border-bottom: 2px solid var(--red); color: var(--text); }
.editor .tol-sub { text-align: center; }
.editor input::placeholder { color: #aaa; }
.btn-icon { width: 2rem; height: 2rem; border: 0; border-radius: 6px; background: none; color: var(--muted); font-size: 1.3rem; cursor: pointer; }
.btn-icon:hover { background: #fbeaea; color: var(--red); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 1rem 1.5rem; margin: 0; }
.facts dt { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.facts dd { margin: .15rem 0 0; font-weight: 600; }
.facts .wide { grid-column: 1 / -1; }
.control td:first-child { white-space: nowrap; font-weight: 600; }
.control-notes { margin: .8rem 0 1.2rem; font-size: .92rem; }
.page-head form { margin: 0; }

/* Characteristics editor: automatic L.p. from row order, row actions, client dialog */
#rows { counter-reset: row; }
#rows .char-row { counter-increment: row; }
#rows .lp { width: 2.6rem; text-align: center; font-weight: 600; color: var(--muted); }
#rows .lp::before { content: counter(row); }
.row-actions { white-space: nowrap; }
.btn-small { padding: .3rem .7rem; font-size: .88rem; justify-self: start; }
.client-field { display: grid; align-content: start; gap: .5rem; }
dialog { border: 0; border-radius: var(--radius); padding: 1.5rem; width: min(30rem, 92vw); box-shadow: 0 16px 48px rgb(0 0 0 / .3); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog .form label { display: grid; gap: .35rem; font-weight: 600; font-size: .95rem; }
dialog .form input { width: 100%; padding: .6rem .75rem; font: inherit; font-weight: 400; border: 1px solid #cfcfcf; border-radius: 8px; }
.editor select[name$="-method"] { min-width: 9.5rem; }

/* Stage 4: series grid, event form, journal timeline */
.check { display: inline-flex !important; align-items: center; gap: .45rem; font-weight: 500 !important; cursor: pointer; }
.check input { width: 1.1rem; height: 1.1rem; min-height: 0 !important; accent-color: var(--red); }
.grid-table { border-collapse: collapse; width: 100%; }
.grid-table th, .grid-table td { border: 1px solid var(--line); padding: .3rem .4rem; text-align: center; }
.grid-table thead th { font-size: .82rem; font-weight: 600; background: #fafafa; }
.grid-table th.char { text-align: left; min-width: 14rem; background: #fafafa; font-size: .9rem; }
.grid-table th small { display: block; font-weight: 400; color: var(--muted); }
.grid-table input, .grid-table select { width: 100%; min-width: 5rem; padding: .4rem; text-align: center; }
.grid-table td.bad { background: #fbeaea; color: var(--red-dark); font-weight: 600; }
.grid-table td.bad input, .grid-table td.bad select { border-color: var(--red); color: var(--red-dark); }
.checks { border: 0; padding: 0; margin: 0; display: grid; gap: .3rem; }
.checks legend { font-weight: 600; font-size: .95rem; margin-bottom: .35rem; padding: 0; }
.timeline { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; }
.entry { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem 1rem; }
.entry-event { border-left: 4px solid #8a9099; }
.entry p { margin: .4rem 0 0; }
.entry-head { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1rem; cursor: pointer; }
.entry-edit { margin-left: auto; }
.entry details[open] .table-scroll { margin-top: .7rem; }
.badge-ok { background: #eef6f0; color: var(--ok); }
.badge-event { background: #ececee; color: var(--graphite); }
