/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue-dark:   #1a3a5c;
  --blue-mid:    #1e5799;
  --blue-accent: #2f80c8;
  --blue-light:  #d6e8f7;
  --blue-pale:   #eef5fb;
  --text:        #1a1a2e;
  --text-muted:  #5a6a80;
  --border:      #c2d8ee;
  --white:       #ffffff;
  --red:         #c0392b;
  --green:       #1a7a4a;
  --radius:      6px;
  --shadow:      0 2px 8px rgba(0,0,0,.12);
}

html, body { height: 100%; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; color: var(--text); background: var(--blue-pale); }

/* ── Header ──────────────────────────────────────────────────────────────── */
#header {
  background: linear-gradient(135deg, var(--blue-dark) 0%, var(--blue-mid) 100%);
  color: var(--white);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
  position: sticky; top: 0; z-index: 100;
}
#header h1 { font-size: 20px; letter-spacing: .5px; font-weight: 600; }
#header h1 span { font-weight: 300; opacity: .75; font-size: 14px; margin-left: 10px; }
#header-actions { display: flex; gap: 10px; }

/* ── Main layout ─────────────────────────────────────────────────────────── */
#app { max-width: 900px; margin: 24px auto 60px; padding: 0 16px; }

/* ── Card / section ──────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  background: var(--blue-pale);
  border-bottom: 1px solid var(--border);
  padding: 10px 18px;
  font-weight: 600;
  font-size: 13px;
  color: var(--blue-dark);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.card-body { padding: 18px; }

/* ── Form grid ────────────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
.form-grid.one-col { grid-template-columns: 1fr; }
.full-width { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; }
.field input, .field select, .field textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 14px;
  color: var(--text);
  background: var(--white);
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--blue-accent);
  box-shadow: 0 0 0 3px rgba(47,128,200,.15);
}
.field textarea { resize: vertical; min-height: 70px; }
.field select { appearance: auto; }

/* ── Checkboxes ───────────────────────────────────────────────────────────── */
.checkbox-list { display: flex; flex-direction: column; gap: 10px; }
.checkbox-item { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.checkbox-item input[type="checkbox"] {
  width: 17px; height: 17px; margin-top: 1px; cursor: pointer;
  accent-color: var(--blue-accent); flex-shrink: 0;
}
.checkbox-item .cb-label { font-size: 14px; line-height: 1.4; }

/* ── Hardware modifications ───────────────────────────────────────────────── */
#hard-mod-section { margin-top: 12px; padding: 14px 14px 10px; background: var(--blue-pale); border-radius: var(--radius); border: 1px solid var(--border); }
#hard-mod-section label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; display: block; margin-bottom: 8px; }
.hard-mod-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.hard-mod-row input { flex: 1; border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px; font-size: 14px; }
.hard-mod-row input:focus { outline: none; border-color: var(--blue-accent); box-shadow: 0 0 0 3px rgba(47,128,200,.15); }
.btn-remove-mod { background: none; border: none; color: var(--red); cursor: pointer; font-size: 18px; line-height: 1; padding: 2px 4px; }
.btn-remove-mod:hover { opacity: .7; }

/* ── Location row ─────────────────────────────────────────────────────────── */
.location-row { display: flex; gap: 12px; align-items: center; }
.location-row input[type="text"] { flex: 1; border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 10px; font-size: 14px; }
.location-row input[type="text"]:focus { outline: none; border-color: var(--blue-accent); box-shadow: 0 0 0 3px rgba(47,128,200,.15); }
.location-row label { display: flex; align-items: center; gap: 6px; font-size: 14px; white-space: nowrap; cursor: pointer; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 600; cursor: pointer;
  border: none; transition: filter .15s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--blue-accent); color: var(--white); }
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary { background: var(--white); color: var(--blue-dark); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--blue-pale); }
.btn-danger { background: var(--red); color: var(--white); }
.btn-danger:hover { filter: brightness(1.1); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-generate {
  width: 100%; padding: 14px; font-size: 16px; letter-spacing: .5px;
  background: linear-gradient(135deg, var(--blue-mid), var(--blue-accent));
  color: var(--white); border: none; border-radius: var(--radius);
  cursor: pointer; font-weight: 700; transition: filter .15s;
  box-shadow: 0 3px 10px rgba(30,87,153,.35);
}
.btn-generate:hover { filter: brightness(1.08); }
.btn-generate:disabled { opacity: .6; cursor: not-allowed; }

/* ── Status area ─────────────────────────────────────────────────────────── */
#status-area { margin-top: 14px; display: none; }
#status-area.visible { display: block; }
.status-success { background: #e8f5ee; border: 1px solid #a3d9b5; border-radius: var(--radius); padding: 14px 18px; color: var(--green); }
.status-error   { background: #fdf0ef; border: 1px solid #f5bbb7; border-radius: var(--radius); padding: 14px 18px; color: var(--red); }
.status-loading { background: var(--blue-pale); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; color: var(--blue-dark); }
.status-success a { color: var(--green); font-weight: 700; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 200;
  align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--white); border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  width: min(960px, 95vw); max-height: 88vh;
  display: flex; flex-direction: column;
}
.modal-header {
  background: var(--blue-dark); color: var(--white);
  padding: 14px 20px; display: flex; align-items: center; justify-content: space-between;
  border-radius: 8px 8px 0 0; flex-shrink: 0;
}
.modal-header h2 { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--white); font-size: 22px; cursor: pointer; line-height: 1; }
.modal-close:hover { opacity: .75; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0; }

/* ── DB table ─────────────────────────────────────────────────────────────── */
.db-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.db-table th { background: var(--blue-pale); color: var(--text-muted); text-transform: uppercase; font-size: 11px; letter-spacing: .3px; padding: 8px 10px; text-align: left; border-bottom: 2px solid var(--border); }
.db-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.db-table tr:hover td { background: var(--blue-pale); }
.db-table .actions { display: flex; gap: 6px; }

/* ── Form inside modal ────────────────────────────────────────────────────── */
.modal-form { display: flex; flex-direction: column; gap: 12px; }
.modal-form .field label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; display: block; margin-bottom: 4px; }
.modal-form .field input, .modal-form .field textarea, .modal-form .field select { width: 100%; border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 10px; font-size: 14px; }
.modal-form .field input:focus, .modal-form .field textarea:focus, .modal-form .field select:focus { outline: none; border-color: var(--blue-accent); box-shadow: 0 0 0 3px rgba(47,128,200,.15); }
.modal-form .field textarea { min-height: 90px; resize: vertical; }

.multi-check-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 24px;
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}
.multi-check-grid label {
  display: flex !important;
  flex-direction: row !important;
  justify-content: space-between;
  align-items: center;
  min-height: 36px;
  min-width: 0;
  width: 100%;
  padding: 4px 8px;
  box-sizing: border-box;
  cursor: pointer;
  font-size: 13px;
  writing-mode: horizontal-tb !important;
  white-space: nowrap;
  word-break: normal;
}
.modal-form .field .multi-check-grid label {
  display: flex !important;
  flex-direction: row !important;
  justify-content: space-between;
  align-items: center;
  min-height: 36px;
  min-width: 0;
  width: auto !important;
  padding: 4px 8px;
  box-sizing: border-box;
  margin-bottom: 0;
  font-weight: 400;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  writing-mode: horizontal-tb !important;
  white-space: nowrap;
  word-break: normal;
}
.multi-check-grid label span { flex: 1; min-width: 0; overflow-wrap: break-word; white-space: normal; }
.multi-check-grid input[type="checkbox"],
.modal-form .field .multi-check-grid input[type="checkbox"] {
  width: auto !important;
  flex-shrink: 0;
  accent-color: var(--blue-accent);
  margin-left: 10px;
}

/* ── Office combobox ──────────────────────────────────────────────────────── */
.combobox-wrap { position: relative; width: 100%; }
.combobox-wrap input[type="text"] {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 7px 10px; font-size: 14px; color: var(--text); background: var(--white);
  transition: border-color .15s, box-shadow .15s;
}
.combobox-wrap input[type="text"]:focus {
  outline: none; border-color: var(--blue-accent);
  box-shadow: 0 0 0 3px rgba(47,128,200,.15);
}
.combobox-list {
  display: none; position: absolute; top: calc(100% + 2px); left: 0; right: 0;
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); z-index: 300; max-height: 220px; overflow-y: auto;
  list-style: none; padding: 4px 0; margin: 0;
}
.combobox-list.open { display: block; }
.combobox-item { padding: 8px 12px; font-size: 14px; cursor: pointer; color: var(--text); }
.combobox-item:hover { background: var(--blue-pale); }
.combobox-noresult { padding: 8px 12px; font-size: 13px; color: var(--text-muted); cursor: default; }
.combobox-add { padding: 8px 12px; font-size: 13px; font-weight: 600; color: var(--blue-accent); cursor: pointer; border-top: 1px solid var(--border); margin-top: 2px; }
.combobox-add:hover { background: var(--blue-pale); }

/* ── Tags / badges ────────────────────────────────────────────────────────── */
.tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.6;
  margin: 2px 2px 2px 0;
  white-space: nowrap;
}
.tag-sow     { background: var(--blue-light); color: var(--blue-dark); }
.tag-green   { background: #d4edda; color: var(--green); }
.tag-mission { background: #ebebeb; color: #444; }
.tag-muted   { background: none; color: var(--text-muted); font-weight: 400; }
.tags-cell   { line-height: 2; }

/* ── Divider ──────────────────────────────────────────────────────────────── */
hr.modal-divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ── Spinner ──────────────────────────────────────────────────────────────── */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--blue-accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--blue-pale); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
