/* DevisPlus - minimal styling, no CSS framework */

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: #1f2430;
  background: #f7f8fa;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: #1f2430;
  color: #fff;
}

.topbar .brand {
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  font-size: 1.1rem;
}

.topbar nav a {
  color: #d7dae0;
  text-decoration: none;
  margin-left: 1.25rem;
}

.topbar nav a:hover {
  color: #fff;
}

.content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Pages that need the whole viewport (the grid): drop the centered column. */
.content.content-wide {
  max-width: none;
  padding: 0;
}

.panel {
  background: #fff;
  border: 1px solid #e2e4e9;
  border-radius: 6px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.panel h2 {
  margin-top: 0;
}

.hint {
  color: #6b7280;
  font-size: 0.9rem;
}

.alert-error {
  background: #fde7ec;
  border: 1px solid #f3b4c5;
  color: #9c2749;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}

.alert-ok {
  background: #e6f4ea;
  border: 1px solid #a9d9bb;
  color: #1c6b34;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}

.muted { color: #6b7280; }

form label {
  display: block;
  margin-bottom: 0.75rem;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"] {
  display: block;
  margin-top: 0.25rem;
  padding: 0.4rem;
  border: 1px solid #cfd3da;
  border-radius: 4px;
  width: 100%;
  max-width: 320px;
}

button {
  background: #2f6fed;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.95rem;
}

button:hover {
  background: #2557c7;
}

.grid-table {
  width: 100%;
  border-collapse: collapse;
}

.grid-table th,
.grid-table td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid #e2e4e9;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 1rem;
}

.toolbar label {
  margin-bottom: 0;
  font-size: 0.85rem;
}

.toolbar input {
  width: 100px;
}

.floating-footer {
  position: sticky;
  bottom: 0;
  background: #1f2430;
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: 6px;
  margin-top: 1rem;
  font-weight: 600;
}

/* ===================================================================
   Grid page (templates/grid.html + static/js/grid.js)
   =================================================================== */

/* Full-bleed layout for the grid page: it needs more width than the
   default centered .content column. */
.grid-page {
  max-width: none;
  padding: 1rem 1.25rem 0;
}

.grid-page h1 {
  margin: 0 0 0.75rem;
  font-size: 1.35rem;
}

/* Header / action panel ------------------------------------------------ */
.grid-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
  padding: 0.9rem 1rem;
}

.coef-group {
  display: flex;
  gap: 0.75rem;
  padding-right: 1rem;
  margin-right: 0.25rem;
  border-right: 1px solid #e2e4e9;
}

.coef-group label {
  margin-bottom: 0;
  font-size: 0.78rem;
  color: #4b5162;
  font-weight: 600;
}

.coef-group input {
  width: 84px;
  margin-top: 0.2rem;
}

.grid-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-left: auto;
}

.grid-actions button,
.grid-actions .btn-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  text-decoration: none;
  font-size: 0.9rem;
  line-height: 1.2;
}

.btn-secondary {
  background: #eef1f6;
  color: #1f2430;
  border: 1px solid #d3d8e2;
}
.btn-secondary:hover { background: #e2e7f0; }

button[disabled],
.grid-actions button[disabled] {
  opacity: 0.6;
  cursor: progress;
}

/* Small inline spinner shown on buttons during async actions. */
.btn-spinner {
  width: 13px;
  height: 13px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  display: inline-block;
  animation: dp-spin 0.7s linear infinite;
}
@keyframes dp-spin { to { transform: rotate(360deg); } }

/* Status legend -------------------------------------------------------- */
.status-legend {
  display: flex;
  gap: 1rem;
  align-items: center;
  font-size: 0.8rem;
  color: #4b5162;
  margin: 0 0 0.6rem;
  padding-left: 0.2rem;
}
.status-legend .swatch {
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 3px;
  margin-right: 0.35rem;
  vertical-align: -1px;
  border: 1px solid rgba(0,0,0,0.12);
}
.swatch-green { background: #e6f4ea; }
.swatch-orange { background: #fef3e2; }
.swatch-pink { background: #fde7ec; }

/* The AG Grid host --------------------------------------------------- */
#grid {
  width: 100%;
  height: calc(100vh - 260px);
  min-height: 420px;
}

/* ===================================================================
   AG Grid visual overrides (Theming API 'quartz' base)
   Row background by matching status. Higher specificity + !important so
   they beat the theme's own row background.
   =================================================================== */
.ag-row.row-green  { background-color: #e6f4ea !important; }
.ag-row.row-orange { background-color: #fef3e2 !important; }
.ag-row.row-pink   { background-color: #fde7ec !important; }

/* Keep a readable hover tint on colored rows. */
.ag-row.row-green.ag-row-hover  { background-color: #d8eede !important; }
.ag-row.row-orange.ag-row-hover { background-color: #f9e9cf !important; }
.ag-row.row-pink.ag-row-hover   { background-color: #f7d7e0 !important; }

/* Chapter rows: full-width bold group rows. */
.chapter-row {
  display: flex;
  align-items: center;
  height: 100%;
  width: 100%;
  padding: 0 0.6rem;
  font-weight: 700;
  color: #1f2430;
  background: #eef1f6;
  border-bottom: 1px solid #d3d8e2;
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chapter-row .chapter-num {
  color: #2f6fed;
  margin-right: 0.5rem;
}

/* PU retenu column: bold value. */
.pu-cell { font-weight: 700; }

/* A selected price cell gets a blue border. */
.ag-cell.cell-selected {
  border: 2px solid #2f6fed !important;
  background-color: rgba(47, 111, 237, 0.08) !important;
  border-radius: 3px;
}

/* Clickable price cells: subtle affordance. */
.ag-cell.price-cell { cursor: pointer; }
.ag-cell.price-cell:hover { background-color: rgba(47, 111, 237, 0.06); }

/* Status badge shown in-cell. */
.status-badge {
  display: inline-block;
  padding: 0.08rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.4;
}
.status-badge.green  { background: #cdecd6; color: #1c6b34; }
.status-badge.orange { background: #fbe0b8; color: #8a5a0f; }
.status-badge.pink   { background: #f7cdd9; color: #9c2749; }

/* Floating footer (already sticky in base styles) — grid variant. */
.grid-page .floating-footer {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin: 0;
  border-radius: 0;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.floating-footer .footer-total { color: #9fe0b4; }

/* Toast notifications -------------------------------------------------- */
.toast-area {
  position: fixed;
  right: 1rem;
  bottom: 4.2rem;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 360px;
}
.toast {
  background: #1f2430;
  color: #fff;
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  font-size: 0.88rem;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
  animation: dp-fade 0.2s ease-out;
}
.toast.error { background: #9c2749; }
.toast.success { background: #1c6b34; }
@keyframes dp-fade { from { opacity: 0; transform: translateY(6px); } }

/* ===================================================================
   Mapping page (templates/mapping.html)
   =================================================================== */
.mapping-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.9rem 1.25rem;
  margin-bottom: 0.5rem;
}
.mapping-grid label,
.mapping-field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: #4b5162;
  margin-bottom: 0.75rem;
}
.mapping-grid select,
.mapping-field select {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.4rem;
  border: 1px solid #cfd3da;
  border-radius: 4px;
  background: #fff;
  font-size: 0.9rem;
}

.price-col-list {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.6rem;
}
.price-col-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid #e2e4e9;
  border-radius: 5px;
  padding: 0.45rem 0.6rem;
}
.price-col-list input[type="text"] {
  margin: 0;
  flex: 1;
  max-width: none;
  padding: 0.3rem 0.4rem;
}
.price-col-list input[type="checkbox"] { flex: none; }

.preview-wrap {
  overflow-x: auto;
  border: 1px solid #e2e4e9;
  border-radius: 6px;
  max-height: 480px;
}
.preview-table {
  border-collapse: collapse;
  font-size: 0.82rem;
  white-space: nowrap;
}
.preview-table th,
.preview-table td {
  border: 1px solid #eceef2;
  padding: 0.3rem 0.55rem;
  text-align: left;
}
.preview-table thead th {
  position: sticky;
  top: 0;
  background: #f2f4f8;
  z-index: 1;
}
.preview-table tr.header-row td {
  background: #fff6e0;
  font-weight: 700;
}
.preview-table .rownum {
  color: #9aa0ac;
  background: #f7f8fa;
  position: sticky;
  left: 0;
}

/* ===================================================================
   Authentication: login card, account page, admin user management
   =================================================================== */

/* Centered narrow column for login / account. */
.content.content-narrow {
  max-width: 520px;
}

.login-card {
  margin-top: 3rem;
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.6rem;
}

.stack-form button {
  margin-top: 0.25rem;
}

/* Signed-in identity block on the right of the top bar. */
.topbar-user {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin-left: 1.5rem;
  padding-left: 1.25rem;
  border-left: 1px solid rgba(255, 255, 255, 0.25);
}

.topbar-user a {
  margin-left: 0;
  font-weight: 600;
}

.topbar-user form { display: inline; }

.topbar-user button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: inherit;
  padding: 0.2rem 0.6rem;
  font-size: 0.85rem;
}

.topbar-user button:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* User list table. */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid #e9ebef;
  vertical-align: middle;
}

.data-table th {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: #6b7280;
}

/* Inline "reset password" form inside a table cell. */
.inline-form {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.inline-form input[type="password"] {
  margin-top: 0;
  max-width: 190px;
}

.role-badge {
  display: inline-block;
  padding: 0.08rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.role-badge.role-admin { background: #dbe4fb; color: #1f4bb8; }
.role-badge.role-user  { background: #e9ebef; color: #4b5563; }

.btn-danger {
  background: #b3243f;
}

.btn-danger:hover {
  background: #8e1c32;
}

select {
  display: block;
  margin-top: 0.25rem;
  padding: 0.4rem;
  border: 1px solid #cfd3da;
  border-radius: 4px;
  width: 100%;
  max-width: 320px;
}
