:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-soft: #f2f5f9;
  --text: #111827;
  --muted: #667085;
  --line: #d7dee8;
  --line-strong: #b8c2cf;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #dbeafe;
  --danger: #dc2626;
  --ok: #15803d;
  --shadow: 0 14px 34px rgba(17, 24, 39, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 62px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  color: var(--text);
  font-size: 20px;
  font-weight: 850;
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav a {
  min-height: 36px;
  padding: 8px 11px;
  border-radius: 8px;
  color: #344054;
  font-weight: 750;
}

.nav a:hover { background: var(--surface-soft); }
.logout { margin-left: auto; }

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 26px auto 56px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

h1, h2 { margin: 0; line-height: 1.16; letter-spacing: 0; }
h1 { font-size: 31px; font-weight: 850; }
h2 { font-size: 18px; font-weight: 820; }
p { margin: 7px 0 0; color: var(--muted); }

.secondary-heading { margin: 12px 0; }
.layout { display: grid; gap: 20px; }
.layout > * { min-width: 0; }
.two-columns { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
.stack { display: grid; gap: 14px; }

.panel,
.auth-panel,
.item-card,
.set-card,
.active-strip {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel, .auth-panel { padding: 19px; }
.narrow { max-width: 640px; margin: 0 auto; }
.auth-panel { max-width: 420px; margin: 80px auto 0; }

.list { display: grid; gap: 10px; }
.embedded { margin-top: 14px; }
.mini-list { display: grid; gap: 8px; margin: 12px 0 16px; }

.item-card,
.set-card,
.active-strip {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  padding: 15px;
}

.item-card.simple { align-items: center; }
.item-title { color: var(--text); font-size: 18px; font-weight: 820; }
.empty { padding: 18px; color: var(--muted); background: var(--surface-soft); border: 1px dashed var(--line-strong); border-radius: 8px; }
.muted { color: var(--muted); }

.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }

label { color: #344054; font-weight: 760; }
.form p { display: grid; gap: 7px; margin: 0; }
.compact textarea { min-height: 92px; }

input, select, textarea {
  width: 100%;
  min-height: 43px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  font: inherit;
  outline: none;
}

textarea { min-height: 140px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 41px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 13px;
  background: #fff;
  color: #1f2937;
  font: inherit;
  font-weight: 820;
  cursor: pointer;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: center;
}

button:hover, .button:hover { border-color: var(--primary); color: var(--primary-dark); }
.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.primary:hover { background: var(--primary-dark); color: #fff; }
.danger { color: var(--danger); }
.large { min-height: 52px; font-size: 17px; }
.full { width: 100%; }
.icon-button {
  width: 40px;
  min-width: 40px;
  padding: 0;
  flex: 0 0 40px;
  white-space: nowrap;
  overflow-wrap: normal;
}
.icon-button svg, .button svg, button svg { width: 18px; height: 18px; }
.link-button { border: 0; padding: 0; min-height: auto; background: transparent; }

.messages { display: grid; gap: 8px; margin-bottom: 16px; }
.message { padding: 11px 13px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.message.success { border-color: #bbf7d0; background: #f0fdf4; color: #166534; }
.message.error { border-color: #fecaca; background: #fef2f2; color: #991b1b; }
.errorlist { margin: 0; padding-left: 18px; color: var(--danger); }

.active-strip { align-items: center; margin-bottom: 18px; }
.active-strip span { display: block; color: var(--muted); margin-top: 3px; }

.timer {
  position: sticky;
  top: 72px;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  margin: 0 0 18px auto;
  padding: 8px;
  background: #111827;
  color: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.timer span {
  min-width: 70px;
  padding: 0 8px;
  font-size: 22px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.timer button {
  width: 40px;
  min-width: 40px;
  border-color: rgba(255,255,255,.2);
  background: rgba(255,255,255,.08);
  color: #fff;
}

.set-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.set-line span {
  padding: 4px 8px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: #1e3a8a;
  font-weight: 760;
}

.sets { display: grid; gap: 10px; margin-top: 14px; }
.set-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
.set-card details { grid-column: 1 / -1; margin-top: 8px; }
.parts { display: grid; gap: 7px; margin: 10px 0; }
.part-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.inline-grid { display: grid; grid-template-columns: 74px 1fr 1fr 1.2fr auto; gap: 8px; }

.history-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.history-item:first-child { padding-top: 0; }
.history-item:last-child { border-bottom: 0; padding-bottom: 0; }
.history-item ul { margin: 8px 0 0; padding-left: 20px; }

.sticky-panel { position: sticky; top: 144px; }
.quick-form input[name="quick"] { min-height: 54px; font-size: 18px; }
.manual-entry { margin: 14px 0; }
.manual-entry summary { cursor: pointer; font-weight: 820; }
.manual-entry form { margin-top: 12px; }

@media (max-width: 820px) {
  .topbar { align-items: flex-start; flex-wrap: wrap; gap: 8px; padding: 10px 14px; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .page { width: min(100% - 20px, 1180px); margin-top: 16px; }
  h1 { font-size: 25px; }
  .section-heading { align-items: stretch; flex-direction: column; }
  .two-columns { grid-template-columns: 1fr; }
  .item-card, .active-strip { padding: 13px; }
  .actions { justify-content: flex-start; }
  .timer { width: 100%; justify-content: center; top: 104px; margin-left: 0; }
  .sticky-panel { position: static; }
  .inline-grid { grid-template-columns: 1fr 1fr; }
  .inline-grid button { grid-column: 1 / -1; }
}

@media (max-width: 520px) {
  body { font-size: 14px; }
  .brand { font-size: 18px; }
  .nav a { padding-inline: 9px; }
  .item-card, .set-card { flex-direction: column; }
  .set-card { display: flex; }
  .item-title { font-size: 17px; }
  button, .button { width: 100%; }
  .icon-button {
    width: 42px;
    min-width: 42px;
    flex-basis: 42px;
  }
  .actions button:not(.icon-button), .actions .button:not(.icon-button) {
    width: auto;
    min-width: min(100%, 96px);
    flex: 1 1 96px;
  }
  .actions .icon-button {
    width: 42px;
    min-width: 42px;
    flex: 0 0 42px;
  }
  .actions form { display: inline-flex; }
}
