/* RF3 Document Generator - Web App Styles */
/* Brand: Primary #152C48, Secondary #3D5A73, Accent #C4953A, Text #2D2D2D, Light #E8E8E8 */

:root {
  --primary: #152C48;
  --secondary: #3D5A73;
  --accent: #C4953A;
  --text: #2D2D2D;
  --light: #E8E8E8;
  --bg: #f5f5f5;
  --white: #ffffff;
  --border: #ddd;
  --danger: #c62828;
  --success: #2e7d32;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* Nav */
.nav {
  background: var(--primary);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
}

.nav-inner {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 24px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}

.nav-logo {
  height: 32px;
}

/* Container */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* Flash messages */
.flash {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 20px;
  font-size: 14px;
}

.flash-error { background: #fce4ec; color: var(--danger); border: 1px solid #f8bbd0; }
.flash-success { background: #e8f5e9; color: var(--success); border: 1px solid #c8e6c9; }

/* Page header */
.page-header {
  margin-bottom: 28px;
}

.page-header h1 {
  font-size: 28px;
  color: var(--primary);
  margin-bottom: 4px;
}

.page-header p {
  color: var(--secondary);
  font-size: 15px;
}

/* Template grid */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.template-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 24px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.template-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 16px rgba(21, 44, 72, 0.1);
}

.template-card-icon {
  width: 40px;
  height: 40px;
  color: var(--accent);
  margin-bottom: 14px;
}

.template-card-icon svg {
  width: 100%;
  height: 100%;
}

.template-card h3 {
  font-size: 17px;
  color: var(--primary);
  margin-bottom: 6px;
}

.template-card p {
  font-size: 13px;
  color: var(--secondary);
  line-height: 1.4;
}

/* Form */
.doc-form {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

fieldset.form-section {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  background: var(--white);
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

fieldset.form-section legend {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 8px;
}

/* Fields */
.field {
  flex: 1 1 280px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-full {
  flex: 1 1 100%;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.field input,
.field select,
.field textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(196, 149, 58, 0.15);
}

.field textarea {
  resize: vertical;
  min-height: 80px;
}

/* List groups (repeatable rows) */
.list-group {
  flex: 1 1 100%;
}

.list-group-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 8px;
}

.list-items {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

.list-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}

.list-item-fields {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.list-item-fields .field {
  flex: 1 1 160px;
  min-width: 0;
}

.list-item-fields .field label {
  font-size: 10px;
}

.list-item-fields .field input,
.list-item-fields .field select {
  padding: 7px 10px;
  font-size: 13px;
}

/* Remove button */
.btn-remove {
  background: none;
  border: none;
  color: #999;
  font-size: 16px;
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  line-height: 1;
  margin-top: 18px;
  transition: color 0.15s, background 0.15s;
}

.btn-remove:hover {
  color: var(--danger);
  background: #fce4ec;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: background 0.15s, box-shadow 0.15s;
}

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

.btn-primary:hover {
  background: #b3862f;
  box-shadow: 0 2px 8px rgba(196, 149, 58, 0.3);
}

.btn-secondary {
  background: var(--white);
  color: var(--secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg);
  border-color: var(--secondary);
}

.btn-large {
  padding: 14px 32px;
  font-size: 16px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding-top: 8px;
}

/* Success page */
.success-page {
  text-align: center;
  padding: 48px 0;
}

.success-icon {
  width: 64px;
  height: 64px;
  color: var(--success);
  margin: 0 auto 20px;
}

.success-icon svg {
  width: 100%;
  height: 100%;
}

.success-page h1 {
  font-size: 28px;
  color: var(--primary);
  margin-bottom: 8px;
}

.success-detail {
  color: var(--secondary);
  margin-bottom: 32px;
}

.success-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 32px;
}

.success-meta {
  color: var(--secondary);
  font-size: 13px;
}

.success-meta code {
  background: var(--light);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 12px;
}

.success-meta p {
  margin-bottom: 4px;
}

/* ── Pricing Pages ── */

/* Header with button */
.pricing-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* Back link */
.back-link {
  display: inline-block;
  font-size: 13px;
  color: var(--secondary);
  text-decoration: none;
  margin-bottom: 8px;
}

.back-link:hover {
  color: var(--accent);
}

/* Card actions */
.pricing-card {
  display: flex;
  flex-direction: column;
  position: relative;
}

.card-delete {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 24px;
  height: 24px;
  padding: 4px;
  border: none;
  background: none;
  color: #ccc;
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.card-delete:hover {
  color: var(--danger);
  background: #fce4ec;
}

.card-delete svg {
  width: 100%;
  height: 100%;
}

.pricing-card-meta {
  font-size: 12px;
  color: var(--secondary);
  margin-bottom: 12px;
}

.pricing-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
  padding-top: 16px;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
}

/* Section labels for list pages */
.section-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 24px 0 12px;
}

.section-label:first-of-type {
  margin-top: 0;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 64px 0;
  color: var(--secondary);
}

.empty-state p {
  margin-bottom: 20px;
  font-size: 15px;
}

/* ── Editable Pricing Matrix ── */

.pricing-matrix-section {
  flex-direction: column;
}

.matrix-wrapper {
  width: 100%;
  overflow-x: auto;
}

.pricing-matrix-edit {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 12px;
}

.pricing-matrix-edit th {
  background: var(--primary);
  color: #fff;
  padding: 8px 6px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}

.pricing-matrix-edit th .thickness-input {
  width: 48px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  padding: 4px;
  border-radius: 4px;
}

.pricing-matrix-edit th .thickness-input:focus {
  background: rgba(255,255,255,0.25);
  outline: none;
  border-color: var(--accent);
}

.pricing-matrix-edit .matrix-corner {
  text-align: right;
  padding-right: 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.pricing-matrix-edit td {
  padding: 2px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.pricing-matrix-edit .height-cell {
  background: var(--bg);
  padding: 4px 8px;
  text-align: right;
}

.pricing-matrix-edit .height-input {
  width: 48px;
  border: 1px solid transparent;
  background: transparent;
  text-align: right;
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  padding: 4px;
  border-radius: 4px;
}

.pricing-matrix-edit .height-input:focus {
  border-color: var(--accent);
  background: var(--white);
  outline: none;
}

.pricing-matrix-edit .price-input {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  text-align: center;
  font-size: 14px;
  color: var(--text);
  padding: 6px 4px;
  border-radius: 4px;
  font-variant-numeric: tabular-nums;
}

.pricing-matrix-edit .price-input:focus {
  border-color: var(--accent);
  background: var(--white);
  outline: none;
  box-shadow: 0 0 0 2px rgba(196, 149, 58, 0.15);
}

.pricing-matrix-edit tbody tr:nth-child(even) td {
  background: #f8f9fa;
}

.pricing-matrix-edit tbody tr:nth-child(even) .height-cell {
  background: #eef0f2;
}

.matrix-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.matrix-actions-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

/* ── Add-on Rows ── */

.addon-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  width: 100%;
}

.addon-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  transition: opacity 0.15s, border-color 0.15s;
}

.addon-row.dragging {
  opacity: 0.4;
}

.addon-row.drag-over {
  border-color: var(--accent);
  box-shadow: 0 -2px 0 0 var(--accent);
}

.addon-fields {
  flex: 1;
  display: flex;
  gap: 10px;
}

.addon-fields .field {
  flex: 1 1 200px;
  min-width: 0;
}

.addon-fields .field label {
  font-size: 10px;
}

.addon-fields .field input {
  padding: 7px 10px;
  font-size: 13px;
}

/* ── Pricing Actions Bar ── */

.pricing-actions {
  position: sticky;
  bottom: 0;
  background: var(--white);
  border-top: 1px solid var(--border);
  padding: 16px 0;
  margin-top: 8px;
  z-index: 10;
}

/* ── Toast Notifications ── */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.3s, transform 0.3s;
  z-index: 100;
}

.toast-show {
  opacity: 1;
  transform: translateY(0);
}

.toast-success {
  background: #e8f5e9;
  color: var(--success);
  border: 1px solid #c8e6c9;
}

.toast-error {
  background: #fce4ec;
  color: var(--danger);
  border: 1px solid #f8bbd0;
}

/* ── Nav Links ── */

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-links {
  display: flex;
  gap: 20px;
}

.nav-links a {
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: color 0.15s;
}

.nav-links a:hover {
  color: #fff;
}

/* Nav user menu */
.nav-user {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.nav-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
}

.nav-user-name {
  color: rgba(255,255,255,0.8);
  font-size: 13px;
  font-weight: 500;
}

.nav-logout {
  color: rgba(255,255,255,0.5);
  text-decoration: none;
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  transition: all 0.15s;
}

.nav-logout:hover {
  color: #fff;
  border-color: rgba(255,255,255,0.5);
}

/* Login page */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--primary);
}

.login-card {
  background: var(--white);
  border-radius: 12px;
  padding: 48px 40px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  text-align: center;
}

.login-header {
  margin-bottom: 28px;
}

.login-logo {
  height: 64px;
  margin-bottom: 16px;
}

.login-header h1 {
  font-size: 22px;
  color: var(--primary);
  margin-bottom: 8px;
}

.login-header p {
  font-size: 14px;
  color: var(--secondary);
}

.login-card .flash {
  text-align: left;
  margin-bottom: 16px;
}

.google-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 28px;
  background: var(--white);
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  transition: all 0.15s;
  cursor: pointer;
}

.google-btn:hover {
  border-color: var(--secondary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* ── Slab Pricing Items ── */

.pricing-items-section {
  flex-direction: column;
}

.section-hint {
  font-size: 12px;
  color: var(--secondary);
  font-style: italic;
  margin-bottom: 12px;
}

.slab-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  width: 100%;
}

.slab-item-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  transition: opacity 0.15s, border-color 0.15s;
}

.slab-item-row.dragging {
  opacity: 0.4;
}

.slab-item-row.drag-over {
  border-color: var(--accent);
  box-shadow: 0 -2px 0 0 var(--accent);
}

.drag-handle {
  cursor: grab;
  color: #aaa;
  font-size: 16px;
  padding: 4px 2px;
  user-select: none;
  align-self: center;
  transition: color 0.15s;
}

.drag-handle:hover {
  color: var(--primary);
}

.drag-handle:active {
  cursor: grabbing;
}

.slab-item-fields {
  flex: 1;
  display: flex;
  gap: 10px;
}

.slab-field-name {
  flex: 2 1 200px !important;
}

.slab-field-price {
  flex: 1 1 100px !important;
}

.slab-field-unit {
  flex: 1 1 100px !important;
}

.slab-item-fields .field label {
  font-size: 10px;
}

.slab-item-fields .field input {
  padding: 7px 10px;
  font-size: 13px;
}
