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

:root {
  --color-primary:    #1F4E79;
  --color-primary-lt: #2E75B6;
  --color-accent:     #0078D4;
  --color-bg:         #F3F6FA;
  --color-surface:    #FFFFFF;
  --color-border:     #D0D7E0;
  --color-text:       #1A1A2E;
  --color-text-muted: #6B7280;
  --color-success:    #107C10;
  --color-error:      #A4262C;
  --color-warning:    #C57700;
  --color-row-alt:    #EDF4FB;
  --radius:           8px;
  --shadow:           0 2px 8px rgba(0,0,0,0.10);
  --font:             'Segoe UI', system-ui, -apple-system, sans-serif;
}

html, body {
  font-family: var(--font);
  font-size: 15px;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.app-header {
  background: var(--color-primary);
  color: #fff;
  padding: 16px 32px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
}

.app-header .logo {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.app-header .subtitle {
  font-size: 13px;
  opacity: 0.75;
  margin-top: 2px;
}

.user-box {
  margin-left: auto;
  position: relative;
}

.user-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.28);
  color: #fff;
  font-family: var(--font);
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.user-trigger:hover { background: rgba(255,255,255,0.24); }

.user-name {
  font-size: 13px;
  font-weight: 600;
}

.user-trigger .caret { font-size: 11px; opacity: 0.8; }

/* ── Account menu ──────────────────────────────────────────────────────────── */
.user-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 250px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.22);
  overflow: hidden;
  z-index: 150;
}

.user-menu-head {
  padding: 12px 16px;
  font-size: 12.5px;
  color: var(--color-text-muted);
  background: #F8FAFC;
  border-bottom: 1px solid var(--color-border);
  word-break: break-all;
}

.user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 14px;
  color: var(--color-text);
  cursor: pointer;
  border-bottom: 1px solid #EEF2F7;
}

.user-menu-item:last-child { border-bottom: none; }
.user-menu-item:hover { background: #EBF3FB; }

/* ── Modal dialog ──────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,25,40,0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 16px;
  z-index: 300;
  overflow-y: auto;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: 0 18px 48px rgba(0,0,0,0.32);
  width: 100%;
  max-width: 860px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--color-border);
}

.modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
  color: var(--color-primary);
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 26px;
  line-height: 1;
  color: var(--color-text-muted);
  cursor: pointer;
  width: 34px;
  height: 34px;
  border-radius: 6px;
}

.modal-close:hover { background: #F0F3F7; color: var(--color-error); }

.modal-body { padding: 24px; }

/* ── Sign-in gate ──────────────────────────────────────────────────────────── */
.auth-card {
  max-width: 460px;
  margin: 60px auto 0;
  text-align: center;
  padding: 36px 32px;
}

.auth-lock { font-size: 40px; line-height: 1; margin-bottom: 12px; }

.auth-title {
  font-size: 20px;
  color: var(--color-primary);
  margin-bottom: 10px;
}

.auth-text {
  font-size: 14px;
  color: var(--color-text-muted);
  line-height: 1.6;
  margin-bottom: 22px;
}

.auth-status {
  margin-top: 16px;
  font-size: 13px;
  color: var(--color-error);
  min-height: 18px;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 28px;
  margin-bottom: 24px;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title .step-badge {
  background: var(--color-primary);
  color: #fff;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}

/* ── Form controls ─────────────────────────────────────────────────────────── */
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 160px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

select, input[type="date"], input[type="number"], input[type="text"] {
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: var(--font);
  background: #fff;
  color: var(--color-text);
  transition: border-color 0.15s;
  outline: none;
  height: 38px;
}

select:focus, input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(0,120,212,0.15);
}

select { cursor: pointer; padding-right: 28px; }

/* ── Searchable project picker ─────────────────────────────────────────────── */
.combo {
  position: relative;
}

.combo input[type="text"] {
  width: 100%;
  padding-right: 34px;
}

.combo-clear {
  position: absolute;
  right: 6px;
  top: 5px;
  width: 26px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
}

.combo-clear:hover { background: #EBF3FB; color: var(--color-error); }

.combo-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 50;
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.14);
}

.combo-list li {
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 1px solid #EEF2F7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.combo-list li:last-child { border-bottom: none; }
.combo-list li:hover,
.combo-list li.active { background: #EBF3FB; }
.combo-list li.chosen { font-weight: 700; color: var(--color-primary); }

.combo-list li.combo-empty {
  cursor: default;
  color: var(--color-text-muted);
  font-style: italic;
  white-space: normal;
}

.combo-list li.combo-empty:hover { background: #fff; }

/* Row beneath the input row: options + history pill. Keeping these out of
   .form-row matters — .form-row bottom-aligns its columns, so an extra element
   inside one form-group pushes that group's input out of line with the others. */
.row-below {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.chk-inline {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
  white-space: nowrap;
}

.chk-inline input[type="checkbox"] { cursor: pointer; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 20px;
  border-radius: 6px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
  height: 38px;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
}

.btn-primary:hover { background: #005fa3; }

.btn-success {
  background: var(--color-success);
  color: #fff;
  padding: 10px 24px;
  height: auto;
  font-size: 15px;
}

.btn-success:hover { background: #0b5e0b; }

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Admin: user management ────────────────────────────────────────────────── */
.admin-badge { background: var(--color-text-muted); }

.admin-intro {
  font-size: 14px;
  color: var(--color-text-muted);
  line-height: 1.6;
  margin-bottom: 18px;
}

.admin-add { align-items: flex-end; }

.btn-danger-sm {
  background: #FDE7E9;
  color: var(--color-error);
  border: 1px solid #e8a0a4;
  padding: 4px 12px;
  height: 28px;
  font-size: 12.5px;
  border-radius: 5px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
}

.btn-danger-sm:hover { background: #f9d2d6; }

.tag-protected {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #EBF3FB;
  color: var(--color-primary);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ── Status / info pills ───────────────────────────────────────────────────── */
.info-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}

.info-pill.history { background: #FFF4CE; color: var(--color-warning); }
.info-pill.no-history { background: #F3F3F3; color: var(--color-text-muted); }
.info-pill.success-pill { background: #DFF6DD; color: var(--color-success); }
.info-pill.error-pill { background: #FDE7E9; color: var(--color-error); }

/* ── Invoice table ─────────────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  background: var(--color-primary);
  color: #fff;
  padding: 11px 14px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}

thead th:first-child { border-radius: var(--radius) 0 0 0; }
thead th:last-child  { border-radius: 0 var(--radius) 0 0; }

tbody tr:nth-child(even) { background: var(--color-row-alt); }
tbody tr:hover { background: #D6EAFD; }

tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody td.center { text-align: center; }

tfoot tr {
  background: #BDD7EE;
  font-weight: 700;
}

tfoot td {
  padding: 10px 14px;
  border-top: 2px solid var(--color-primary-lt);
}

tfoot td.num { text-align: right; }

/* ── Destination toggle ────────────────────────────────────────────────────── */
.dest-toggle {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.dest-option {
  flex: 1 1 220px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 13px 16px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  background: #fff;
  transition: border-color 0.15s, background 0.15s;
}

.dest-option:hover { border-color: var(--color-primary-lt); }

.dest-option.selected {
  border-color: var(--color-accent);
  background: #EBF3FB;
}

.dest-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.dest-option .dest-label {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-primary);
}

.dest-option .dest-hint {
  font-size: 12.5px;
  color: var(--color-text-muted);
  line-height: 1.4;
}

.dest-note {
  font-size: 14px;
  color: var(--color-text);
  line-height: 1.6;
  background: #F8FAFC;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.dest-note em { color: var(--color-text-muted); font-size: 13px; }

/* ── Folder browser ────────────────────────────────────────────────────────── */
.folder-browser {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.folder-breadcrumb {
  background: #EBF3FB;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--color-primary);
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.folder-breadcrumb span { cursor: pointer; }
.folder-breadcrumb span:hover { text-decoration: underline; }
.folder-breadcrumb .sep { color: var(--color-text-muted); }

.folder-list {
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
}

.folder-list li {
  padding: 9px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
  border-bottom: 1px solid var(--color-border);
  font-size: 14px;
  transition: background 0.1s;
}

.folder-list li:hover { background: #EBF3FB; }
.folder-list li.selected { background: #DBEAFE; font-weight: 600; }
.folder-list li .folder-icon { font-size: 16px; }

.selected-folder-display {
  margin-top: 10px;
  font-size: 13px;
  color: var(--color-primary);
  font-weight: 600;
}

/* ── Markup field ──────────────────────────────────────────────────────────── */
.markup-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.markup-row label {
  font-weight: 600;
  font-size: 14px;
}

.markup-row input {
  width: 100px;
}

.markup-summary {
  font-size: 14px;
  color: var(--color-text-muted);
}

.markup-summary strong {
  color: var(--color-primary);
}

/* ── Loader spinner ────────────────────────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid #c5d7e8;
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast notifications ───────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease;
  max-width: 360px;
}

.toast.success { background: #DFF6DD; color: var(--color-success); border: 1px solid #a3d9a3; }
.toast.error   { background: #FDE7E9; color: var(--color-error); border: 1px solid #e8a0a4; }
.toast.info    { background: #EBF3FB; color: var(--color-primary); border: 1px solid #a0bfdf; }

@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ── Section visibility helpers ────────────────────────────────────────────── */
.hidden { display: none !important; }

.section-divider {
  border: none;
  border-top: 2px solid var(--color-border);
  margin: 4px 0 20px;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 680px) {
  .app-header { padding: 14px 18px; }
  .container  { padding: 18px 12px 50px; }
  .card       { padding: 18px 16px; }
  .form-row   { flex-direction: column; gap: 12px; }
  .form-group { min-width: 100%; }
  select, input { width: 100%; }
}
