:root {
  --ink: #111d28;
  --ink-soft: #4c5b67;
  --paper: #f4f1eb;
  --card: #fffdfa;
  --line: #ddd8cf;
  --red: #d7302f;
  --red-dark: #a91e21;
  --orange: #ef7a32;
  --green: #267157;
  --navy: #152534;
  --navy-2: #213a4f;
  --shadow: 0 18px 50px rgba(24, 31, 36, 0.08);
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: Inter, "Segoe UI", Arial, sans-serif; font-size: 16px; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; }
.topbar { min-height: 88px; padding: 0 clamp(20px, 4vw, 64px); display: flex; align-items: center; gap: 28px; color: white; background: var(--navy); border-bottom: 4px solid var(--red); }
.brand-link { display: flex; align-items: center; gap: 13px; color: white; text-decoration: none; }
.brand-link > span:last-child { display: flex; flex-direction: column; }
.brand-link strong { margin-top: 2px; font-size: 25px; line-height: 1; letter-spacing: -.4px; }
.brand-mark { width: 46px; height: 52px; display: grid; place-items: center; position: relative; overflow: hidden; background: var(--red); clip-path: polygon(50% 0, 100% 18%, 91% 78%, 50% 100%, 9% 78%, 0 18%); font-family: Consolas, monospace; font-weight: 800; }
.brand-mark::before { content: ""; width: 15px; height: 18px; position: absolute; top: 8px; background: #ffb13b; border-radius: 70% 15% 60% 40%; transform: rotate(8deg); }
.brand-mark span { margin-top: 19px; font-size: 10px; letter-spacing: 1px; z-index: 1; }
.topbar h1 { margin: 1px 0 0; font-size: 25px; line-height: 1; letter-spacing: -0.4px; }
.eyebrow { margin: 0; color: var(--red); font-size: 12px; font-weight: 800; letter-spacing: 1.6px; text-transform: uppercase; }
.topbar .eyebrow { color: #ff8a7c; }
.draft-state { margin-left: auto; display: flex; align-items: center; gap: 9px; color: #d6e0e7; font-size: 14px; }
.main-menu { align-self: stretch; display: flex; align-items: stretch; gap: 4px; }
.main-menu a, .user-menu a, .user-menu button { display: flex; align-items: center; padding: 0 13px; color: #d7e0e6; background: transparent; border: 0; border-bottom: 3px solid transparent; font-size: 14px; font-weight: 750; text-decoration: none; }
.main-menu a:hover, .main-menu a.active, .user-menu a:hover, .user-menu a.active { color: white; border-bottom-color: var(--red); }
.user-menu { margin-left: auto; display: flex; align-items: center; gap: 5px; }
.user-menu form { margin: 0; }
.user-menu button { min-height: 42px; padding: 0 11px; color: #bfcbd3; border: 1px solid #526471; border-radius: 5px; }
.user-menu button:hover { color: white; border-color: #82919b; }
.draft-strip { padding: 9px clamp(20px, 4vw, 64px); display: flex; justify-content: flex-end; color: white; background: var(--navy-2); }
.draft-strip .draft-state { margin-left: 0; }
.status-dot { width: 8px; height: 8px; background: #ffad42; border-radius: 50%; box-shadow: 0 0 0 4px rgba(255, 173, 66, 0.12); }
.saved-dot { background: #67c59b; box-shadow: 0 0 0 4px rgba(103, 197, 155, .15); }

.planner-grid { width: min(1500px, 100%); margin: 0 auto; display: grid; grid-template-columns: minmax(360px, 0.78fr) minmax(560px, 1.35fr); align-items: start; }
.control-panel { min-height: calc(100vh - 124px); padding: 38px clamp(24px, 3vw, 46px) 60px; background: #eae6df; border-right: 1px solid #d2ccc2; }
.planning-panel { min-width: 0; padding: 38px clamp(24px, 4vw, 60px) 70px; }
.panel-heading { display: flex; justify-content: space-between; gap: 24px; align-items: end; padding-bottom: 24px; border-bottom: 1px solid #cec8bf; }
.panel-heading > div, .section-title { display: flex; gap: 12px; align-items: center; }
.panel-heading h2, .section-title h2, .planning-header h2, .history-heading h2 { margin: 0; font-size: 22px; letter-spacing: -0.4px; }
.panel-heading p, .section-title p { margin: 0; color: var(--ink-soft); font-size: 14px; line-height: 1.5; }
.panel-heading > p { max-width: 190px; text-align: right; }
.step-number { width: 28px; height: 28px; flex: 0 0 28px; display: grid; place-items: center; color: white; background: var(--red); border-radius: 4px; font-family: Consolas, monospace; font-size: 12px; font-weight: 700; }

.form-grid { padding: 24px 0 2px; display: grid; grid-template-columns: 1fr 150px; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 8px; color: #32404b; font-size: 13px; font-weight: 800; letter-spacing: 0.5px; text-transform: uppercase; }
.field-wide { grid-column: 1 / -1; }
.field input, .field textarea, .member-search { width: 100%; color: var(--ink); background: rgba(255,255,255,.72); border: 1px solid #cbc5bb; border-radius: 7px; outline: none; padding: 12px 13px; font-size: 16px; font-weight: 500; letter-spacing: 0; text-transform: none; transition: .18s ease; }
.field input:focus, .field textarea:focus, .member-search:focus { background: white; border-color: var(--red); box-shadow: 0 0 0 3px rgba(215, 48, 47, .09); }
.field textarea { resize: vertical; }
.section-block { margin-top: 28px; padding-top: 27px; border-top: 1px solid #cec8bf; }
.section-title { margin-bottom: 16px; align-items: flex-start; }
.section-title div { display: flex; flex-direction: column; gap: 4px; }

.vehicle-picker { display: grid; gap: 9px; }
.vehicle-option { min-height: 66px; padding: 10px 12px; display: grid; grid-template-columns: 48px 1fr 28px; gap: 12px; align-items: center; text-align: left; color: var(--ink); background: rgba(255,255,255,.55); border: 1px solid #cbc5bb; border-radius: 8px; transition: .18s ease; }
.vehicle-option:hover { border-color: #9d968b; background: white; }
.vehicle-option.active { border-color: var(--navy-2); background: var(--card); box-shadow: 0 5px 16px rgba(20, 33, 43, .06); }
.vehicle-option.locked { cursor: default; }
.vehicle-code { width: 45px; height: 42px; display: grid; place-items: center; color: white; background: var(--navy); border-radius: 5px; font-family: Consolas, monospace; font-size: 10px; font-weight: 800; }
.vehicle-option.active .vehicle-code { background: var(--red); }
.vehicle-option strong, .vehicle-option small { display: block; }
.vehicle-option strong { font-size: 15px; }
.vehicle-option small { margin-top: 3px; color: #6f797f; font-size: 13px; }
.checkmark { width: 25px; height: 25px; display: grid; place-items: center; color: #879097; border: 1px solid #c4beb5; border-radius: 50%; }
.vehicle-option.active .checkmark { color: white; background: var(--green); border-color: var(--green); }

.attendance-summary { margin-bottom: 12px; display: flex; flex-wrap: wrap; gap: 7px; }
.attendance-summary span { padding: 7px 9px; color: #53616b; background: rgba(255,255,255,.62); border: 1px solid #d5cfc6; border-radius: 5px; font-size: 12px; }
.attendance-summary strong { color: var(--ink); }
.member-search { margin-bottom: 10px; background: white; }
.member-list { max-height: 340px; overflow: auto; border: 1px solid #d0cac1; border-radius: 8px; background: rgba(255,255,255,.45); scrollbar-width: thin; }
.member-row { min-height: 56px; padding: 8px 10px; display: grid; grid-template-columns: 36px 1fr 132px; gap: 10px; align-items: center; border-bottom: 1px solid #ddd7ce; }
.member-row:last-child { border-bottom: 0; }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; color: #f7eae6; background: var(--navy-2); border-radius: 50%; font-size: 11px; font-weight: 800; }
.member-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 650; }
.member-row select { width: 100%; padding: 8px; color: #34424c; background: white; border: 1px solid #cfc9c0; border-radius: 5px; font-size: 13px; }
.generate-button { width: 100%; margin-top: 22px; padding: 15px 17px; display: flex; justify-content: space-between; color: white; background: var(--red); border: 0; border-radius: 7px; box-shadow: 0 9px 22px rgba(183, 36, 36, .18); font-weight: 800; transition: .18s ease; }
.generate-button:hover { background: var(--red-dark); transform: translateY(-1px); }

.planning-header { min-height: 60px; display: flex; justify-content: space-between; gap: 20px; align-items: center; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.planning-header .eyebrow, .history-heading .eyebrow { margin-bottom: 5px; }
.capacity-pill { padding: 7px 10px; color: #4e5d68; background: #ebe7e0; border-radius: 20px; font-size: 13px; font-weight: 700; }
.notice { margin: 18px 0; padding: 13px 15px; color: #754a21; background: #fff0dc; border-left: 3px solid var(--orange); border-radius: 4px; font-size: 14px; line-height: 1.5; }
.notice.success { color: #255f49; background: #e5f4ed; border-left-color: var(--green); }
.empty-state { min-height: 400px; padding: 70px 20px; display: grid; place-items: center; align-content: center; text-align: center; border-bottom: 1px solid var(--line); }
.empty-icon { width: 66px; height: 66px; display: grid; place-items: center; color: white; background: var(--navy-2); border: 7px solid #dde2e5; border-radius: 50%; font-size: 28px; }
.empty-state h3 { margin: 19px 0 7px; font-size: 18px; }
.empty-state p { max-width: 500px; margin: 0; color: var(--ink-soft); font-size: 15px; line-height: 1.7; }

.groups-stack { padding-top: 20px; display: grid; gap: 18px; }
.group-card { padding: 20px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.group-topline { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding-bottom: 16px; border-bottom: 1px solid #ebe7df; }
.group-topline h3 { margin: 2px 0 0; font-size: 20px; }
.group-vehicles { display: flex; gap: 8px; }
.group-vehicles button { min-width: 62px; min-height: 42px; padding: 10px 13px; color: #596771; background: #f1eee9; border: 1px solid #cfc8be; border-radius: 6px; font-family: Consolas, monospace; font-size: 14px; font-weight: 800; }
.group-vehicles button.on { color: white; background: var(--navy-2); border-color: var(--navy-2); }
.group-vehicles button:disabled { cursor: default; opacity: 1; }
.vehicle-columns { margin-top: 16px; display: grid; grid-template-columns: repeat(auto-fit, minmax(235px, 1fr)); gap: 12px; }
.vehicle-card { border: 1px solid #e0dbd2; border-radius: 7px; overflow: hidden; }
.vehicle-card-title { padding: 10px 11px; display: flex; align-items: center; gap: 9px; color: white; background: var(--navy); }
.vehicle-card-title span { padding: 4px 5px; color: white; background: var(--red); border-radius: 3px; font-family: Consolas, monospace; font-size: 8px; font-weight: 800; }
.vehicle-card-title strong { font-size: 13px; }
.assignment-row { position: relative; padding: 9px 10px; display: grid; grid-template-columns: 105px 1fr; gap: 8px; align-items: center; border-bottom: 1px solid #ece8e1; }
.assignment-row:last-child { border-bottom: 0; }
.assignment-row > span { color: #5d6870; font-size: 11px; font-weight: 750; text-transform: uppercase; }
.assignment-row select { min-width: 0; width: 100%; padding: 9px 28px 9px 9px; color: var(--ink); background: #f8f6f2; border: 1px solid #d9d4cc; border-radius: 4px; font-size: 13px; }
.assignment-row select:focus { outline: 2px solid rgba(215,48,47,.16); border-color: var(--red); }
.reuse-badge { grid-column: 2; margin-top: -3px; color: #a85b14; font-size: 10px; font-style: normal; font-weight: 800; text-transform: uppercase; }
.stage-button { margin-top: 12px; padding: 8px 0; color: var(--red-dark); background: transparent; border: 0; font-size: 12px; font-weight: 800; }
.reserve-box { padding: 14px 16px; background: #ebe7df; border-radius: 7px; }
.reserve-box strong { font-size: 13px; }
.reserve-box p { margin: 6px 0 0; color: var(--ink-soft); font-size: 12px; line-height: 1.6; }
.save-bar { padding: 16px 17px; display: flex; align-items: center; justify-content: space-between; gap: 18px; color: white; background: var(--navy); border-radius: 8px; }
.save-bar div { display: flex; flex-direction: column; gap: 3px; }
.save-bar strong { font-size: 14px; }
.save-bar span { color: #bac7cf; font-size: 11px; }
.save-actions { display: flex; flex-direction: row !important; align-items: center; gap: 8px !important; }
.save-bar button { flex: 0 0 auto; padding: 11px 14px; color: white; background: var(--red); border: 0; border-radius: 5px; font-size: 13px; font-weight: 800; }
.save-bar .cancel-edit { color: #dbe4ea; background: transparent; border: 1px solid #5d6e7a; }
.save-bar .overview-button { padding: 10px 13px; color: var(--navy); background: white; border: 1px solid white; border-radius: 5px; font-size: 13px; font-weight: 800; text-decoration: none; }
.save-bar button:disabled { cursor: wait; opacity: .7; }

.history-panel { margin-top: 38px; padding-top: 28px; border-top: 1px solid var(--line); }
.history-heading { display: flex; justify-content: space-between; align-items: end; margin-bottom: 12px; }
.history-heading > span { color: #68757e; font-size: 12px; }
.history-row { padding: 13px 4px; display: grid; grid-template-columns: 46px 1fr auto; gap: 13px; align-items: center; border-bottom: 1px solid var(--line); }
.history-row > div:nth-child(2) { display: flex; flex-direction: column; gap: 4px; }
.history-row > div:nth-child(2) strong { font-size: 14px; }
.history-row > div:nth-child(2) span { color: #65727b; font-size: 12px; }
.history-actions { display: flex; gap: 7px; }
.history-actions button,.history-actions a { padding: 8px 10px; background: white; border: 1px solid #cec8bf; border-radius: 5px; font-size: 12px; font-weight: 750; text-decoration: none; }
.history-actions .history-overview { color: var(--green); border-color: #b8d4c8; }
.history-actions .history-edit { color: var(--navy-2); }
.history-actions .history-delete { color: var(--red-dark); border-color: #e1b5b3; }
.date-block { width: 36px; height: 39px; display: grid; place-items: center; align-content: center; color: white; background: var(--navy-2); border-radius: 4px; line-height: 1; }
.date-block strong { font-size: 14px; }
.date-block span { margin-top: 3px; font-size: 8px; text-transform: uppercase; }
.no-history { color: #6a767d; font-size: 13px; }

.page-content { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 48px 0 70px; }
.page-content.narrow { width: min(660px, calc(100% - 40px)); }
.page-title-row { margin-bottom: 26px; display: flex; justify-content: space-between; align-items: end; gap: 24px; }
.page-title-row h1 { margin: 5px 0 7px; font-size: clamp(28px, 4vw, 40px); letter-spacing: -1px; }
.page-title-row p:last-child { margin: 0; color: var(--ink-soft); }
.primary-link, .empty-list a { padding: 13px 16px; color: white; background: var(--red); border-radius: 6px; font-weight: 800; text-decoration: none; }
.exercise-list { overflow: hidden; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.exercise-row { padding: 17px 19px; display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 18px; border-bottom: 1px solid var(--line); }
.exercise-row:last-child { border-bottom: 0; }
.date-block.large { width: 60px; height: 60px; }
.date-block.large strong { font-size: 20px; }
.date-block.large span { font-size: 10px; }
.exercise-details h2 { margin: 0 0 5px; font-size: 19px; }
.exercise-details p { margin: 0; color: var(--ink-soft); font-size: 14px; }
.exercise-actions { display: flex; align-items: center; gap: 8px; }
.exercise-actions form { margin: 0; }
.exercise-actions a, .exercise-actions button { padding: 10px 12px; background: white; border: 1px solid #cec8bf; border-radius: 5px; font-size: 13px; font-weight: 800; text-decoration: none; }
.exercise-actions .overview-link { color: var(--green); border-color: #b8d4c8; }
.exercise-actions .edit-link { color: var(--navy-2); }
.exercise-actions button { color: var(--red-dark); border-color: #e1b5b3; }
.empty-list { padding: 70px 24px; text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.empty-list h2 { margin-top: 0; }
.empty-list p { margin-bottom: 28px; color: var(--ink-soft); }
.form-message { padding: 13px 15px; border-radius: 5px; }
.form-message.success { color: #255f49; background: #e5f4ed; border-left: 3px solid var(--green); }
.form-message.error { color: #8b2828; background: #fae7e7; border-left: 3px solid var(--red); }

.login-page { min-height: 100vh; padding: 24px; display: grid; place-items: center; background: var(--navy); }
.login-card { width: min(460px, 100%); padding: 35px; background: var(--card); border-top: 5px solid var(--red); border-radius: 10px; box-shadow: 0 24px 70px rgba(0,0,0,.28); }
.login-brand { display: flex; align-items: center; gap: 13px; }
.login-brand h1 { margin: 2px 0 0; font-size: 24px; }
.login-card > h2 { margin: 34px 0 5px; font-size: 27px; }
.login-intro { margin: 0 0 22px; color: var(--ink-soft); line-height: 1.55; }
.login-form, .account-form { display: grid; gap: 17px; }
.login-form label, .account-form label { display: grid; gap: 7px; color: #32404b; font-size: 14px; font-weight: 800; }
.login-form input, .account-form input { width: 100%; padding: 13px; color: var(--ink); background: white; border: 1px solid #cfc9c0; border-radius: 6px; outline: none; }
.login-form input:focus, .account-form input:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(215,48,47,.09); }
.login-form button, .account-form button { padding: 14px 16px; color: white; background: var(--red); border: 0; border-radius: 6px; font-weight: 800; }
.account-form { padding: 25px; background: var(--card); border: 1px solid var(--line); border-radius: 9px; box-shadow: var(--shadow); }

.loading-screen { min-height: 100vh; display: grid; place-items: center; align-content: center; gap: 14px; background: var(--navy); color: white; }
.loading-screen p { margin: 0; color: #c6d0d7; font-size: 12px; }
.loader { width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.18); border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; align-content: center; gap: 14px; color: white; background: var(--navy); transition: opacity .2s ease; }
.loading-overlay p { margin: 0; color: #c6d0d7; font-size: 12px; }
.loading-overlay.is-hidden { pointer-events: none; opacity: 0; }

@media (max-width: 1040px) {
  .planner-grid { grid-template-columns: 1fr; }
  .control-panel { min-height: auto; border-right: 0; border-bottom: 1px solid #d2ccc2; }
  .planning-panel { padding-top: 32px; }
  .member-list { max-height: 300px; }
}

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; flex-wrap: wrap; gap: 10px 16px; }
  .brand-mark { width: 40px; height: 46px; }
  .brand-link strong { font-size: 20px; }
  .brand-link .eyebrow { font-size: 9px; }
  .main-menu { width: 100%; order: 3; min-height: 43px; overflow-x: auto; }
  .main-menu a { padding: 0 10px; white-space: nowrap; }
  .user-menu { margin-left: auto; }
  .user-menu a { display: none; }
  .user-menu button { min-height: 38px; }
  .draft-strip { padding-inline: 16px; }
  .control-panel, .planning-panel { padding-inline: 16px; }
  .panel-heading { align-items: flex-start; }
  .panel-heading > p { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .field { grid-column: 1; }
  .member-row { grid-template-columns: 30px 1fr; }
  .member-row select { grid-column: 2; }
  .group-topline, .save-bar { align-items: flex-start; flex-direction: column; }
  .save-bar button { width: 100%; }
  .save-actions { width: 100%; flex-direction: column !important; }
  .history-row { grid-template-columns: 42px 1fr; }
  .history-actions { grid-column: 2; flex-wrap: wrap; }
  .vehicle-columns { grid-template-columns: 1fr; }
  .page-content { width: min(100% - 28px, 1180px); padding-top: 32px; }
  .page-title-row, .exercise-row { align-items: flex-start; }
  .page-title-row { flex-direction: column; }
  .exercise-row { grid-template-columns: 60px 1fr; }
  .exercise-actions { grid-column: 1 / -1; flex-wrap: wrap; }
  .login-card { padding: 25px; }
}
