:root {
  --blue: #0d3767;
  --blue-dark: #07264b;
  --blue-light: #eaf2fb;
  --green: #4f9f35;
  --green-light: #eef8ea;
  --background: #f4f7fb;
  --white: #ffffff;
  --text: #172033;
  --muted: #69778d;
  --border: #dce3ec;
  --danger: #c62828;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--background);
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
.hidden { display: none !important; }

.login-page {
  min-height: 100vh;
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #061d3a, #0d417c);
}

.login-card {
  width: 100%;
  max-width: 420px;
  padding: 40px;
  background: white;
  border-radius: 18px;
  box-shadow: 0 25px 60px rgba(0,0,0,.22);
}

.login-brand { text-align: center; margin-bottom: 30px; }
.logo-placeholder { margin-bottom: 22px; font-size: 30px; font-weight: 800; color: var(--blue); }
.login-brand h1 { margin: 0; font-size: 25px; }
.login-brand p { margin: 8px 0 0; color: var(--muted); }

form { display: flex; flex-direction: column; gap: 16px; }
label { display: flex; flex-direction: column; gap: 7px; font-size: 14px; font-weight: 700; }

input, select {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
}

input:focus, select:focus {
  outline: 2px solid rgba(13,55,103,.12);
  border-color: var(--blue);
}

.primary-button {
  min-height: 45px;
  padding: 11px 18px;
  border: 0;
  border-radius: 8px;
  background: var(--blue);
  color: white;
  font-weight: 700;
}

.primary-button:not(:disabled):hover { background: var(--blue-dark); }

.error-message {
  padding: 10px 12px;
  border-radius: 8px;
  background: #ffeded;
  color: var(--danger);
}

.app-header {
  min-height: 70px;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--blue-dark);
  color: white;
}

.header-brand { display: flex; align-items: center; gap: 20px; }
.header-logo { font-size: 21px; font-weight: 800; }
.header-brand div:last-child { display: flex; flex-direction: column; gap: 3px; }
.header-brand span { font-size: 12px; opacity: .7; }

.header-user { display: flex; align-items: center; gap: 16px; }
.user-data { display: flex; flex-direction: column; text-align: right; }
.user-data small { opacity: .7; text-transform: uppercase; }

.logout-button {
  padding: 8px 13px;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 7px;
  background: transparent;
  color: white;
}

.main-nav {
  padding: 0 24px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  background: white;
  border-bottom: 1px solid var(--border);
}

.nav-button {
  padding: 17px 15px;
  white-space: nowrap;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.nav-button.active { color: var(--blue); border-bottom-color: var(--blue); }

main { padding: 28px; }
.page { display: none; }
.active-page { display: block; }

.page-header {
  margin-bottom: 22px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
}

.page-header h2 { margin: 0 0 5px; font-size: 26px; }
.page-header p { margin: 0; color: var(--muted); }
.filters { display: flex; gap: 10px; }

.kpi-grid {
  margin-bottom: 22px;
  display: grid;
  grid-template-columns: repeat(4,minmax(0,1fr));
  gap: 14px;
}

.kpi-card {
  padding: 20px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.kpi-card span { display: block; margin-bottom: 9px; font-size: 13px; color: var(--muted); }
.kpi-card strong { display: block; margin-bottom: 5px; font-size: 27px; color: var(--blue-dark); }
.kpi-card small { color: var(--muted); }

.panel {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-header {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--border);
}

.panel-header h3 { margin: 0 0 4px; }
.panel-header p { margin: 0; color: var(--muted); }

.panel-title {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 18px;
  font-weight: 800;
}

.green-title { background: var(--green-light); color: #357024; }
.blue-title { background: var(--blue-light); color: var(--blue); }

.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #f8fafc; color: #536176; font-size: 12px; text-transform: uppercase; }
.empty-table { padding: 30px; text-align: center; color: var(--muted); }

.launch-grid {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 18px;
}

.operation-form { padding: 20px; }
.form-row { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }

.wagon-section { padding-top: 10px; }
.wagon-line-label { padding: 10px 20px 0; color: var(--muted); font-size: 13px; }

.wagons-grid {
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(16,minmax(50px,1fr));
  gap: 6px;
  overflow-x: auto;
}

.wagon {
  min-width: 55px;
  padding: 10px 5px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f8fafc;
}

.wagon strong { display: block; margin-bottom: 4px; font-size: 12px; }
.wagon small { display: block; font-size: 10px; color: var(--muted); }

.extra-wagons {
  margin: 20px;
  padding-top: 18px;
  border-top: 3px solid var(--blue);
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  gap: 16px;
}

.admin-card {
  padding: 22px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.admin-card h3 { margin-top: 0; }
.admin-card p { color: var(--muted); line-height: 1.5; }

@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .launch-grid { grid-template-columns: 1fr; }
  .admin-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  main { padding: 18px; }
  .app-header { align-items: flex-start; flex-direction: column; }
  .header-user { width: 100%; justify-content: space-between; }
  .user-data { text-align: left; }
  .page-header { align-items: stretch; flex-direction: column; }
  .filters { flex-direction: column; }
  .kpi-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}

.admin-note {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f5f8fc;
  border: 1px solid var(--border);
  font-size: 13px;
}

textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  resize: vertical;
}
textarea:focus { outline: 2px solid rgba(13,55,103,.12); border-color: var(--blue); }

.admin-tabs {
  margin-bottom: 18px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.admin-tab {
  min-height: 42px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--muted);
  font-weight: 700;
}
.admin-tab.active {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}
.admin-section { display: none; }
.active-admin-section { display: block; }
.admin-layout {
  display: grid;
  grid-template-columns: minmax(300px, .8fr) minmax(0, 1.7fr);
  gap: 18px;
}
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.secondary-button {
  min-height: 45px;
  padding: 11px 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--text);
  font-weight: 700;
}
.compact-input { max-width: 230px; }
.admin-message {
  margin-bottom: 16px;
  padding: 11px 14px;
  border-radius: 8px;
  background: #eef8ea;
  border: 1px solid #cfe7c5;
  color: #285f1d;
}
.admin-message.error {
  background: #ffeded;
  border-color: #f2c5c5;
  color: var(--danger);
}
.user-create-note {
  margin: 16px 20px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #f5f8fc;
  border: 1px solid var(--border);
  color: var(--muted);
}
.action-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.small-button {
  min-height: 34px;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--blue);
  font-weight: 700;
  font-size: 12px;
}
.small-button.danger { color: var(--danger); }
.status-pill {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: #eef2f7;
  color: #526176;
}
.status-pill.on { background: #eef8ea; color: #357024; }

@media (max-width: 1050px) {
  .admin-layout { grid-template-columns: 1fr; }
}

.compact-button { min-height: 40px; padding: 8px 13px; }
.modal-backdrop { position: fixed; inset: 0; z-index: 999; padding: 20px; display:flex; align-items:center; justify-content:center; background:rgba(4,19,38,.64); }
.modal-card { width:min(520px,100%); max-height:calc(100vh - 40px); overflow-y:auto; background:white; border-radius:14px; box-shadow:0 24px 70px rgba(0,0,0,.28); }
.modal-header { padding:18px 20px; display:flex; align-items:flex-start; justify-content:space-between; gap:16px; border-bottom:1px solid var(--border); }
.modal-header h3 { margin:0 0 5px; font-size:20px; }
.modal-header p { margin:0; color:var(--muted); font-size:13px; }
.icon-button { width:38px; height:38px; border:1px solid var(--border); border-radius:8px; background:white; color:var(--text); font-size:22px; line-height:1; }
.temporary-password-box { padding:12px 14px; display:grid; grid-template-columns:1fr auto; gap:3px 12px; align-items:center; border:1px solid #cbd8e7; border-radius:8px; background:#f5f8fc; }
.temporary-password-box span { color:var(--muted); font-size:13px; }
.temporary-password-box strong { color:var(--blue); font-size:17px; }
.temporary-password-box small { grid-column:1 / -1; color:var(--muted); }
