:root {
  --green: #65b32e;
  --green-dark: #166534;
  --green-deep: #0f3f20;
  --ink: #17202a;
  --muted: #687383;
  --line: #dbe3d1;
  --bg: #f4f7f1;
  --card: #ffffff;
  --gold: #d8b24a;
  --danger: #b42318;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top right, rgba(101, 179, 46, .12), transparent 32%), var(--bg);
}
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, rgba(255,255,255,.88), rgba(240,248,235,.92)), url("./assets/logo-la-casa-empresarial.jpeg") center 14% / min(900px, 92vw) auto no-repeat;
}
.login-card {
  width: min(440px, 100%);
  margin-top: 120px;
  padding: 30px;
  border: 1px solid rgba(22, 101, 52, .2);
  border-radius: 10px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 24px 80px rgba(23, 32, 42, .16);
}
.login-logo { width: 210px; max-width: 80%; display: block; margin-bottom: 18px; }
.eyebrow {
  margin: 0 0 6px;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
}
h1 { margin: 0; font-size: clamp(28px, 4vw, 44px); line-height: 1.04; }
h2 { margin: 0 0 16px; font-size: 18px; }
.muted { color: var(--muted); margin: 8px 0 0; }
label { display: grid; gap: 7px; color: #506070; font-size: 12px; font-weight: 800; text-transform: uppercase; }
input, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #c9d7c0;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}
input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(101,179,46,.18); }
.login-card label { margin-top: 14px; }
.login-card button { width: 100%; margin-top: 18px; }
.error { color: var(--danger); min-height: 20px; }

.app { min-height: 100vh; display: grid; grid-template-columns: 290px 1fr; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  background: linear-gradient(180deg, #ffffff, #edf5e8);
  border-right: 1px solid var(--line);
}
.brand { display: grid; gap: 10px; margin-bottom: 30px; }
.brand img { width: 220px; max-width: 100%; }
.brand span { color: var(--green-dark); font-weight: 900; font-size: 12px; text-transform: uppercase; }
nav { display: grid; gap: 10px; }
.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 13px;
  color: var(--ink);
  background: transparent;
  text-align: left;
  font-weight: 800;
}
.nav-btn span {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: rgba(101,179,46,.16);
  color: var(--green-dark);
  font-size: 12px;
}
.nav-btn.active {
  border-color: rgba(101,179,46,.45);
  background: linear-gradient(135deg, rgba(101,179,46,.18), rgba(216,178,74,.12));
}
.sidebar-footer { margin-top: auto; display: grid; gap: 10px; color: var(--muted); font-size: 13px; }
.content { min-width: 0; padding: 28px; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 22px;
}
.primary-btn, .danger-btn, .ghost-btn {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 900;
}
.primary-btn { color: #fff; background: linear-gradient(135deg, var(--green), var(--green-dark)); }
.danger-btn { color: #fff; background: linear-gradient(135deg, #f04438, #991b1b); }
.ghost-btn { color: var(--green-dark); background: #eef7e9; border: 1px solid rgba(101,179,46,.35); }
.toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 170px 170px;
  gap: 14px;
  margin-bottom: 16px;
}
.metric, .panel, .client-group, .status {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,.9);
}
.metric { padding: 12px 14px; }
.metric span { display: block; color: var(--muted); font-size: 11px; font-weight: 900; text-transform: uppercase; }
.metric strong { display: block; font-size: 28px; }
.status { padding: 14px 16px; color: var(--muted); }
.success-panel {
  margin-bottom: 16px;
  padding: 15px 18px;
  border: 1px solid rgba(101,179,46,.45);
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(101,179,46,.18), rgba(216,178,74,.12));
  color: var(--green-dark);
  font-weight: 900;
}
.form-shell {
  overflow: visible;
  min-height: calc(100vh - 190px);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.form-shell iframe {
  display: block;
  width: 100%;
  min-height: calc(100vh - 190px);
  height: 12000px;
  border: 0;
  background: #fff;
}
.documents-list { display: grid; gap: 14px; }
.documents-table-shell {
  overflow: auto;
  border: 1px solid #dfe8d7;
  border-radius: 10px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 16px 50px rgba(23,32,42,.06);
}
.documents-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}
.documents-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 13px 14px;
  background: linear-gradient(135deg, var(--green-dark), var(--green-deep));
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .03em;
  text-align: left;
  text-transform: uppercase;
}
.documents-table td {
  padding: 13px 14px;
  border-top: 1px solid #e4ecdc;
  color: #344255;
  font-size: 13px;
  vertical-align: middle;
}
.documents-table tbody tr:nth-child(even) { background: #f8fbf5; }
.documents-table tbody tr:hover { background: #eef7e9; }
.doc-title {
  max-width: 430px;
  color: var(--ink);
  font-weight: 800;
  line-height: 1.28;
}
.doc-type-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}
.doc-type-pill.contract {
  color: var(--green-dark);
  background: rgba(101,179,46,.16);
  border: 1px solid rgba(101,179,46,.32);
}
.doc-type-pill.quote {
  color: #7a5400;
  background: rgba(216,178,74,.22);
  border: 1px solid rgba(216,178,74,.48);
}
.doc-actions { display: flex; gap: 8px; flex-wrap: nowrap; }
.doc-actions a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 7px;
  background: #edf7e9;
  color: var(--green-dark);
  font-weight: 900;
  text-decoration: none;
}
.doc-actions button { min-height: 36px; padding: 0 12px; }
.settings-grid { display: grid; grid-template-columns: 380px 1fr; gap: 18px; align-items: start; }
.panel { padding: 18px; }
.panel form, .panel label, #userForm { display: grid; gap: 12px; }
.users-list { display: grid; gap: 10px; }
.user-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.user-row strong { display: block; }
.user-row span { color: var(--muted); font-size: 13px; }
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(23,32,42,.46);
  z-index: 20;
}
.modal-card {
  width: min(460px, 100%);
  padding: 22px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 30px 90px rgba(0,0,0,.25);
}
.processing-card {
  border: 1px solid rgba(101,179,46,.28);
  background:
    radial-gradient(circle at top right, rgba(101,179,46,.15), transparent 34%),
    linear-gradient(180deg, #ffffff, #f7fbf3);
}
.processing-card h2 { margin-bottom: 10px; font-size: 24px; }
.processing-card p:not(.eyebrow) {
  margin: 0;
  color: #344255;
  line-height: 1.45;
}
.processing-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  margin-bottom: 14px;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  font-size: 24px;
  font-weight: 900;
  box-shadow: 0 14px 34px rgba(22,101,52,.24);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.document-preview-card {
  width: min(1180px, calc(100vw - 28px));
  height: min(920px, calc(100vh - 28px));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  padding: 0;
  overflow: hidden;
}

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

.document-preview-head h2 {
  margin: 0;
  font-size: 15px;
}

.document-preview-loader {
  padding: 12px 18px;
  color: var(--muted);
  background: #f7fbf3;
  border-bottom: 1px solid var(--line);
}

.document-preview-scroll {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: auto;
  box-sizing: border-box;
  padding: 18px;
  background: #e8eee3;
}

.document-preview-pages {
  display: grid;
  gap: 18px;
}

.document-preview-page {
  width: min(960px, 100%);
  margin: 0 auto;
}

.document-preview-page figcaption {
  margin-top: 8px;
  color: #536177;
  font-size: 12px;
  text-align: center;
}

.document-preview-image {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  box-shadow: 0 14px 42px rgba(23,32,42,.18);
}

.collection-grid {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.collection-form {
  display: grid;
  gap: 12px;
}

textarea {
  width: 100%;
  border: 1px solid #c9d7c0;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
  resize: vertical;
}

textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(101,179,46,.18);
}

.collection-history {
  min-width: 0;
}

.collection-history-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.collection-history-head h2 {
  margin: 0;
}

.collection-orders-list {
  display: grid;
  gap: 10px;
}

.collection-order-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.collection-order-row strong,
.collection-order-row span,
.collection-order-row small {
  display: block;
}

.collection-order-row span {
  margin-top: 4px;
  color: #344255;
}

.collection-order-row small {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.35;
}

.collection-order-meta {
  display: grid;
  gap: 6px;
  justify-items: end;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.mail-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-weight: 900;
}

.mail-status.sent {
  color: var(--green-dark);
  background: rgba(101,179,46,.16);
}

.mail-status.failed {
  color: #7a5400;
  background: rgba(216,178,74,.22);
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .toolbar, .settings-grid, .collection-grid { grid-template-columns: 1fr; }
  .collection-order-row { grid-template-columns: 1fr; }
  .collection-order-meta { justify-items: start; }
  .topbar { flex-direction: column; }
}
