/* ==========================================================================
   CRM dashboard (crm.html)
   A calmer, denser layout than the public pages — built for daily work.
   ========================================================================== */

body {
  background: var(--paper);
  font-size: 0.95rem;
}

.btn-sm {
  min-height: 40px;
  padding: 0.5em 1.1em;
  font-size: 0.85rem;
}

.app {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 22px 16px 0;
  overflow-y: auto;
  background: var(--brown);
  color: var(--cream);
}

/* Sidebar parts keep their size; on short screens the sidebar scrolls instead */
.sidebar > * {
  flex-shrink: 0;
}

/* Scrollbars hidden, scrolling still works (wheel, trackpad, touch, keyboard) */
.sidebar,
.sidebar-nav {
  scrollbar-width: none;      /* Firefox */
  -ms-overflow-style: none;   /* old Edge */
}

.sidebar::-webkit-scrollbar,
.sidebar-nav::-webkit-scrollbar {
  display: none;              /* Chrome, Safari, new Edge */
}

.sidebar .brand {
  color: var(--white);
  margin: 0 8px 20px;
}

.sidebar-label {
  margin: 14px 12px 4px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.55;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Navigation buttons: icon + label (+ lock when unavailable) */
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  text-align: left;
  font-size: 0.9rem;
  color: var(--cream);
  cursor: pointer;
  transition: background 0.2s;
}

.nav-item:hover {
  background: rgba(226, 212, 193, 0.08);
}

.nav-item[aria-current="page"] {
  background: rgba(226, 212, 193, 0.16);
  color: var(--white);
  font-weight: 500;
}

.nav-icon,
.nav-lock {
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-icon {
  width: 19px;
  height: 19px;
}

.nav-label {
  flex: 1;
  white-space: nowrap;
}

/* Locked "coming soon" items: visibly unavailable, go nowhere */
.nav-item.is-locked {
  color: rgba(226, 212, 193, 0.5);
  cursor: not-allowed;
}

.nav-item.is-locked:hover {
  background: none;
}

.nav-lock {
  width: 14px;
  height: 14px;
}

/* Signed-in person: pinned to the bottom of the sidebar so Sign out is always
   visible; on short screens the menu scrolls behind it. */
.sidebar-user {
  position: sticky;
  bottom: 0;
  z-index: 1;
  margin: auto -16px 0;
  padding: 14px 24px 16px;
  border-top: 1px solid rgba(226, 212, 193, 0.16);
  background: var(--brown);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.user-avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--sage);
  color: var(--white);
  font-weight: 600;
}

.user-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-text strong {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-text small {
  font-size: 0.75rem;
  opacity: 0.7;
}

/* Stacked full-width buttons: they always fit the sidebar's width */
.user-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.user-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-width: 0;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid rgba(226, 212, 193, 0.25);
  border-radius: var(--radius-sm);
  background: none;
  font-size: 0.78rem;
  color: var(--cream);
  cursor: pointer;
  white-space: nowrap;
}

.user-btn:hover {
  background: rgba(226, 212, 193, 0.1);
}

.user-btn svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Tablets and phones: a top bar with a scrolling row of navigation buttons */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr; /* top bar keeps its natural height */
  }

  .sidebar {
    position: static;
    height: auto;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 12px var(--gutter) 10px;
    overflow: visible;
  }

  .sidebar .brand {
    margin: 0;
  }

  .sidebar .brand-mark {
    height: 34px;
  }

  .sidebar-label {
    display: none;
  }

  .sidebar-user {
    position: static;
    grid-column: 2;
    grid-row: 1;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
  }

  .user-info {
    display: none;
  }

  /* In the phone top bar the two buttons sit side by side */
  .user-actions {
    flex-direction: row;
  }

  .user-btn {
    width: auto;
    min-height: 36px;
  }

  .sidebar-nav {
    grid-column: 1 / -1;
    flex-direction: row;
    gap: 4px;
    margin: 0 calc(-1 * var(--gutter));
    padding: 0 var(--gutter);
    overflow-x: auto;
    scrollbar-width: none;
  }

  .nav-item {
    flex: none;
    width: auto;
    gap: 8px;
    min-height: 40px;
  }
}

@media (max-width: 480px) {
  .sidebar .brand-name {
    display: none;
  }
}

/* ---------- Main ---------- */
.main {
  padding: clamp(20px, 3vw, 40px);
  min-width: 0; /* lets the table scroll instead of stretching the page */
}

.main-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.main-header .eyebrow {
  margin-bottom: 0.4rem;
}

.main-header h1 {
  font-size: clamp(1.7rem, 3vw, 2.3rem);
  margin: 0;
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---------- Stats ---------- */
/* One strip of figures separated by thin dividers, instead of five boxes */
.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  margin-bottom: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  overflow: hidden;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 20px;
  border-left: 1px solid var(--line);
  margin-left: -1px; /* hides the divider on the first item of each row */
}

.stat-label {
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.stat-value {
  font-family: var(--font-serif);
  font-size: 1.9rem;
  line-height: 1;
  color: var(--brown);
}

/* "New" is the figure the team acts on, so it gets the brand color */
.stat-new .stat-value { color: var(--olive); }

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stat { border-top: 1px solid var(--line); margin-top: -1px; }
}

@media (max-width: 560px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat { padding: 14px 16px; }
  .stat:first-child { grid-column: span 2; }
  .stat-value { font-size: 1.6rem; }
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 18px;
}

.toolbar .field input,
.toolbar .field select {
  min-height: 42px;
  padding: 0.5em 0.8em;
}

@media (max-width: 900px) {
  .toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .search-field {
    grid-column: span 2;
  }
}

/* ---------- Request list ---------- */
.list-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  overflow: hidden;
}

.list-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.result-count {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

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

/* Lets the table scroll sideways on medium screens instead of being cut off */
.table-wrap {
  overflow-x: auto;
}

/* Customer and event columns keep a readable width; the table scrolls if needed */
.requests-table td:nth-child(2) {
  min-width: 180px;
}

.requests-table td:nth-child(3) {
  min-width: 150px;
}

.requests-table[hidden] {
  display: none !important;
}

.requests-table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.requests-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.requests-table tbody tr {
  cursor: pointer;
  transition: background 0.15s;
}

.requests-table tbody tr:hover,
.requests-table tbody tr:focus-within {
  background: rgba(149, 154, 115, 0.1);
}

.requests-table tbody tr:last-child td {
  border-bottom: 0;
}

.row-ref {
  font-family: var(--font-serif);
  font-size: 0.85rem;
  color: var(--olive);
  white-space: nowrap;
}

/* The reference is a real button so rows work with the keyboard */
.row-open {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--line-strong);
}

.cell-main {
  display: block;
  max-width: 240px;
  font-weight: 500;
  color: var(--brown);
  overflow-wrap: break-word; /* long names wrap instead of stretching the table */
}

.cell-sub {
  max-width: 240px;
  overflow-wrap: break-word;
}

.cell-sub {
  display: block;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.muted {
  color: var(--ink-soft);
  font-size: 0.85rem;
  white-space: nowrap;
}

/* Status pills */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  background: var(--paper-deep);
  color: var(--brown);
}

.status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-new            { background: #e8ead9; color: #4d5236; }
.status-contacted      { background: #efe5d3; color: #7a5a1e; }
.status-quotation-sent { background: #f1e1cc; color: #8a4f17; }
.status-confirmed      { background: var(--olive); color: var(--white); }
.status-completed      { background: #e4ddd2; color: #5e5240; }
.status-cancelled      { background: #f0dcd6; color: #8c3a26; }

/* Small screens: each row becomes a card */
@media (max-width: 760px) {
  .requests-table thead {
    display: none;
  }

  .requests-table,
  .requests-table tbody,
  .requests-table tr,
  .requests-table td {
    display: block;
  }

  /* Card layout: reference + status share the first line, details follow */
  .requests-table tbody tr {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    column-gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
  }

  .requests-table td {
    grid-column: 1 / -1;
    padding: 2px 0;
    border: 0;
  }

  .requests-table td.row-ref {
    grid-column: 1;
    grid-row: 1;
  }

  .requests-table td.cell-status {
    grid-column: 2;
    grid-row: 1;
  }

  .requests-table td:nth-child(2) {
    margin-bottom: 4px;
  }

  .cell-main,
  .cell-sub {
    max-width: none;
  }

  .requests-table td[data-label]::before {
    content: attr(data-label) ": ";
    font-size: 0.78rem;
    color: var(--ink-soft);
  }

  /* Event and date read as single lines on a card */
  .requests-table td[data-label] .cell-main,
  .requests-table td[data-label] .cell-sub {
    display: inline;
  }

  .requests-table td[data-label] .cell-sub::before {
    content: " · ";
  }
}

/* ---------- Empty state ---------- */
.empty-state {
  padding: 60px 24px;
  text-align: center;
}

.empty-state[hidden] {
  display: none;
}

.empty-state svg {
  width: 56px;
  height: 56px;
  color: var(--sage);
  margin-bottom: 12px;
}

.empty-state h3 {
  font-size: 1.2rem;
}

.empty-state p {
  max-width: 44ch;
  margin: 0 auto;
  color: var(--ink-soft);
}

/* ---------- Drawer ---------- */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(47, 38, 21, 0.35);
  animation: fadeIn 0.25s both;
}

.drawer-backdrop[hidden],
.drawer[hidden] {
  display: none;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 61;
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  background: var(--paper);
  box-shadow: -20px 0 60px -20px rgba(47, 38, 21, 0.45);
  animation: slideIn 0.35s var(--ease-out) both;
}

@keyframes slideIn {
  from { transform: translateX(40px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 24px 28px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--white);
}

.drawer-ref {
  margin: 0 0 4px;
  font-family: var(--font-serif);
  font-size: 0.85rem;
  color: var(--olive);
}

.drawer-header h2 {
  margin: 0;
  font-size: 1.5rem;
  outline: none;
}

.icon-btn {
  flex: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: none;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--paper-deep);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 22px 28px 40px;
}

.drawer-section {
  margin-bottom: 26px;
}

.drawer-section h3 {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--olive);
  margin-bottom: 10px;
}

.status-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.status-row .field {
  flex: 1;
  min-width: 180px;
}

.quick-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Match the select's height so the row lines up */
.quick-actions .btn-sm {
  min-height: 46px;
}

.detail-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 16px;
  margin: 0;
}

.detail-list dt {
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.detail-list dd {
  margin: 0;
  color: var(--brown);
  overflow-wrap: anywhere;
}

.detail-services {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--white);
}

.detail-services li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}

.detail-services li:last-child {
  border-bottom: 0;
}

.detail-services small {
  color: var(--ink-soft);
}

.notes-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
}

.notes-list li {
  padding: 10px 14px;
  margin-bottom: 8px;
  border-left: 2px solid var(--sage);
  background: var(--white);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.notes-list time {
  display: block;
  font-size: 0.75rem;
  color: var(--ink-soft);
  margin-bottom: 2px;
}

.note-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.note-form textarea {
  min-height: 80px;
}

.danger-zone {
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.btn-danger {
  background: none;
  border-color: rgba(140, 58, 38, 0.4);
  color: #8c3a26;
}

.btn-danger:hover {
  background: #f0dcd6;
}

@media (max-width: 520px) {
  .drawer-header,
  .drawer-body {
    padding-left: 18px;
    padding-right: 18px;
  }

  .detail-list {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .detail-list dd {
    margin-bottom: 10px;
  }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 80;
  transform: translateX(-50%);
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--brown);
  color: var(--white);
  font-size: 0.88rem;
  box-shadow: var(--shadow-soft);
  animation: fadeIn 0.2s both;
}

.toast[hidden] {
  display: none;
}

/* ==========================================================================
   Views, account management and password dialog
   ========================================================================== */
.view[hidden] {
  display: none;
}

.main-header h1 {
  outline: none;
}

/* Add-account dialog: two columns of fields, one column on phones */
.account-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 18px;
}

.account-form .span-2 {
  grid-column: 1 / -1;
}

@media (max-width: 600px) {
  .account-form {
    grid-template-columns: 1fr;
  }
}

.field-hint {
  font-size: 0.76rem;
  color: var(--ink-soft);
}

.inline-input {
  display: flex;
  gap: 8px;
}

.inline-input input {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

.inline-input .btn-sm {
  min-height: 46px;
}

.form-message {
  margin: 0;
  font-size: 0.85rem;
  color: #9a3b2a;
}

.form-message:empty {
  display: none;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* One-time sign-in details after creating an account / resetting a password */
.credentials p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.credentials-list {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--paper);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  margin: 0;
}

.credentials-list dt {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.credentials-list dd {
  margin: 0;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.95rem;
  color: var(--brown);
  user-select: all;
  overflow-wrap: anywhere;
}

.list-title {
  margin: 0 0 2px;
  font-size: 1.05rem;
}

/* Accounts table (same look as the requests table) */
.accounts-table {
  width: 100%;
  border-collapse: collapse;
}

.accounts-table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.accounts-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.accounts-table tbody tr:last-child td {
  border-bottom: 0;
}

.accounts-table td:first-child {
  min-width: 170px;
}

.cell-actions {
  white-space: nowrap;
  text-align: right;
}

.cell-actions .btn-sm {
  min-height: 34px;
  padding: 0.3em 0.9em;
  font-size: 0.8rem;
}

.cell-actions .btn + .btn {
  margin-left: 4px;
}

.you-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--cream);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--brown);
  vertical-align: middle;
}

@media (max-width: 760px) {
  .accounts-table thead {
    display: none;
  }

  .accounts-table,
  .accounts-table tbody,
  .accounts-table td {
    display: block;
  }

  .accounts-table tbody tr {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    column-gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
  }

  .accounts-table td {
    grid-column: 1 / -1;
    padding: 2px 0;
    border: 0;
  }

  .accounts-table td:first-child {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
  }

  .accounts-table td.cell-status {
    grid-column: 2;
    grid-row: 1;
  }

  .accounts-table td[data-label]::before {
    content: attr(data-label) ": ";
    font-size: 0.78rem;
    color: var(--ink-soft);
  }

  .cell-actions {
    display: flex !important;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    text-align: left;
  }

  .cell-actions .btn + .btn {
    margin-left: 0;
  }
}

/* Dialogs: change password, add account */
.modal {
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink);
  box-shadow: var(--shadow-soft);
}

.modal-wide {
  width: min(560px, calc(100vw - 32px));
}

.modal[open] {
  animation: modalIn 0.22s var(--ease-out) both;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.modal::backdrop {
  background: rgba(47, 38, 21, 0.4);
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
}

/* The add-account dialog swaps between its two steps with the hidden attribute */
.modal-form[hidden] {
  display: none;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head .icon-btn {
  width: 36px;
  height: 36px;
}

.modal-form h2 {
  margin: 0;
  font-size: 1.3rem;
}
