/* Zephyr app shell (F07-S01): left navigation, top bar, record-page template and the shared parts
   every screen uses. All values come from tokens.css. Below 768 px the navigation is a drawer. */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-width: 320px; min-height: 100vh;
  font-family: var(--font-family); font-size: var(--font-size-md); line-height: var(--line-height);
  font-weight: var(--font-weight-normal); color: var(--color-ink); background: var(--color-canvas);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
a { color: inherit; }
.icon { display: block; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.75; }

/* Keyboard focus is always visible. */
:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.sidebar :focus-visible { outline-color: var(--brand-sand); }

.skip-link {
  position: absolute; top: var(--space-2); left: var(--space-2); z-index: 50; padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm); color: var(--color-on-primary); background: var(--color-primary);
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Sidebar */
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 30; width: var(--sidebar-width); padding: 26px var(--space-4) var(--space-5);
  display: flex; flex-direction: column; color: var(--sidebar-text); background: var(--sidebar-bg); overflow-y: auto;
}
.brand { height: 46px; display: flex; align-items: center; gap: var(--space-3); padding: 0 var(--space-2); }
.brand-logo { display: block; height: 26px; width: auto; }
.icon-button.sidebar-close { display: none; }
.nav { margin-top: 28px; }
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-group + .nav-group { margin-top: var(--space-4); }
.nav-label {
  margin: 0 var(--space-3) var(--space-2); color: var(--sidebar-label);
  font-size: 10px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase;
}
.nav-item {
  width: 100%; min-height: 44px; margin-bottom: 4px; padding: 0 var(--space-3); border-radius: var(--radius-md);
  display: flex; align-items: center; gap: 13px; color: var(--sidebar-text); text-decoration: none; font-size: var(--font-size-md);
}
/* A row shown under the one above it, without an icon, as in the prototype (Time summary under Time entries). */
.nav-item--nested { min-height: 36px; padding-left: 45px; color: var(--sidebar-label); font-size: var(--font-size-sm); }
.nav-item:hover { color: var(--sidebar-hover-text); background: var(--sidebar-hover); }
.nav-item[aria-current="page"] { color: var(--sidebar-active-text); background: var(--sidebar-active-bg); font-weight: var(--font-weight-strong); }
.nav-bottom { margin-top: auto; padding-top: var(--space-4); border-top: 1px solid var(--sidebar-divider); }

/* Main column and top bar */
.main { min-height: 100vh; margin-left: var(--sidebar-width); }
.topbar {
  min-height: var(--topbar-height); padding: var(--space-4) 42px; display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  border-bottom: 1px solid var(--color-line); background: var(--topbar-bg);
}
.title-wrap { min-width: 0; display: flex; align-items: center; gap: 14px; }
.title-wrap > div { min-width: 0; }
.eyebrow { margin: 0 0 var(--space-1); color: var(--color-muted); font-size: var(--font-size-xs); }
h1 {
  margin-bottom: 0; color: var(--color-ink); font-size: var(--font-size-2xl); font-weight: var(--font-weight-heading);
  letter-spacing: -.025em; overflow-wrap: anywhere;
}
.top-actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.icon-button.menu-button { display: none; }

.icon-button {
  width: 40px; height: 40px; padding: 0; border: 1px solid var(--color-line); border-radius: var(--radius-md);
  display: grid; place-items: center; color: var(--color-ink); background: var(--color-surface);
}
.search-trigger {
  position: relative; height: 40px; padding: 0 10px 0 13px; border: 1px solid var(--color-line); border-radius: var(--radius-md);
  display: flex; align-items: center; gap: 9px; color: var(--color-muted); background: var(--color-surface); min-width: 220px;
}
.search-trigger .search-text { flex: 1; text-align: left; font-size: var(--font-size-sm); }
kbd {
  padding: 2px 5px; border: 1px solid var(--color-line); border-radius: 4px; color: var(--color-muted);
  background: var(--color-canvas); font-family: inherit; font-size: 11px;
}
.primary-button {
  position: relative; height: 40px; padding: 0 16px; border: 0; border-radius: var(--radius-md); display: inline-flex; align-items: center; gap: var(--space-2);
  color: var(--color-on-primary); background: var(--color-primary); box-shadow: var(--shadow-button);
  font-size: var(--font-size-sm); font-weight: var(--font-weight-strong); text-decoration: none;
}
.primary-button:hover { background: var(--color-primary-hover); }
.secondary-button {
  height: 40px; padding: 0 14px; border: 1px solid var(--color-line); border-radius: var(--radius-md);
  display: inline-flex; align-items: center; gap: var(--space-2); background: var(--color-surface); font-size: var(--font-size-sm);
}
.user-button {
  position: relative; height: 40px; padding: 0 var(--space-2) 0 4px; border: 1px solid var(--color-line); border-radius: 999px;
  display: flex; align-items: center; gap: var(--space-2); background: var(--color-surface); max-width: 220px;
}
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--font-size-sm); }
.avatar {
  display: grid; place-items: center; flex: 0 0 auto; width: 32px; height: 32px; border-radius: 50%;
  color: var(--avatar-text); background: var(--brand-sand); font-size: 11px; font-weight: 750;
}

/* Pop-up menus ("+ New", user menu) */
.menu-wrap { position: relative; }
.menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 40; min-width: 200px; margin: 0; padding: var(--space-1);
  list-style: none; border: 1px solid var(--color-line); border-radius: var(--radius-md); background: var(--color-surface); box-shadow: var(--shadow-menu);
}
.menu[hidden] { display: none; }
.menu-item {
  width: 100%; min-height: 40px; padding: 0 var(--space-3); border: 0; border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: var(--space-2); background: transparent; text-align: left; text-decoration: none; font-size: var(--font-size-sm);
}
.menu-item:hover, .menu-item:focus { background: var(--color-canvas); }
.menu-note { margin: 0; padding: var(--space-2) var(--space-3); color: var(--color-muted); font-size: var(--font-size-xs); }

/* Search dialog (the search itself comes with F07-S04) */
.dialog {
  width: min(560px, calc(100vw - 32px)); padding: var(--space-6); border: 1px solid var(--color-line); border-radius: var(--radius-lg);
  color: var(--color-ink); background: var(--color-surface); box-shadow: var(--shadow-menu);
}
.dialog::backdrop { background: var(--backdrop); }
.dialog h2 { font-size: var(--font-size-lg); }

/* Page content */
.content { max-width: var(--content-max-width); margin: 0 auto; padding: 30px 42px 48px; }
.content:focus { outline: none; }
.panel {
  padding: var(--space-5); border: 1px solid var(--color-line-soft); border-radius: var(--radius-lg);
  background: var(--color-surface); box-shadow: var(--shadow-panel);
}
.panel + .panel { margin-top: var(--space-4); }
.panel h2 { margin-bottom: var(--space-3); font-size: var(--font-size-lg); font-weight: var(--font-weight-heading); }
.muted { color: var(--color-muted); }
.status-line { min-height: 1.4em; margin: var(--space-3) 0 0; font-weight: var(--font-weight-strong); }
.error { color: var(--color-red); }

/* Lists */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: var(--font-size-sm); }
.data-table th {
  padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--color-line); color: var(--color-muted);
  font-size: var(--font-size-xs); font-weight: var(--font-weight-strong); text-align: left; white-space: nowrap;
}
.data-table td { padding: var(--space-3); border-bottom: 1px solid var(--color-line-soft); vertical-align: top; overflow-wrap: anywhere; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table a { font-weight: var(--font-weight-strong); text-decoration: none; }
.data-table a:hover { text-decoration: underline; }
.list-toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.list-toolbar p { margin: 0; }

/* Record-page template: header with key fields and actions, main column, side column. Used by every
   record page (Account 360 in F07-S06, opportunities in F09, projects in F11). */
.record-header {
  display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--space-4);
  margin-bottom: var(--space-5);
}
.key-fields { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-6); margin: 0; }
.key-fields div { min-width: 0; }
.key-fields dt { color: var(--color-muted); font-size: var(--font-size-xs); }
.key-fields dd { margin: 0; font-weight: var(--font-weight-strong); overflow-wrap: anywhere; }
.record-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.record-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: var(--space-4); align-items: start; }
.record-main, .record-side { min-width: 0; }
.details { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-3) var(--space-5); margin: 0; }
.details dt { color: var(--color-muted); font-size: var(--font-size-xs); }
.details dd { margin: 0; overflow-wrap: anywhere; }
.record-audit { margin: var(--space-4) 0 0; font-size: var(--font-size-xs); }
.related-list { list-style: none; margin: 0; padding: 0; }
.related-list li { padding: var(--space-2) 0; border-bottom: 1px solid var(--color-line-soft); }
.related-list li:last-child { border-bottom: 0; }
.related-list a { font-weight: var(--font-weight-strong); text-decoration: none; }
.related-list a:hover { text-decoration: underline; }
.related-list small { display: block; color: var(--color-muted); }

/* Forms (create form built from the field metadata) */
.record-form fieldset { margin: 0 0 var(--space-4); padding: var(--space-4); border: 1px solid var(--color-line); border-radius: var(--radius-md); }
.record-form legend { padding: 0 var(--space-1); font-weight: var(--font-weight-strong); }
.field { margin: 0 0 var(--space-3); }
.field-caption { margin-bottom: var(--space-1); font-weight: var(--font-weight-strong); font-size: var(--font-size-sm); }
.field .required-mark { color: var(--color-red); }
.field input[type=text], .field input[type=number], .field input[type=date], .field input[type=datetime-local],
.field input[type=tel], .field input[type=email], .field input[type=url],
.field textarea, .field select {
  width: 100%; min-height: 40px; padding: var(--space-2) var(--space-3); border: 1px solid var(--color-line);
  border-radius: var(--radius-sm); background: var(--color-input);
}
.field .pair { display: flex; gap: var(--space-2); }
.field small { display: block; margin-top: var(--space-1); color: var(--color-muted); font-size: var(--font-size-xs); }
.field .error { display: block; font-size: var(--font-size-xs); }
.form-buttons { display: flex; flex-wrap: wrap; gap: var(--space-2); }
/* The quick "Add contact" form in the account's Contacts panel (F07-S03) */
.compact-form { margin-bottom: var(--space-4); padding-bottom: var(--space-3); border-bottom: 1px solid var(--color-line-soft); }
.compact-form fieldset { padding: 0; border: 0; }

/* A short warning next to a value, for example "No consent" next to an email address (F07-S03) */
.badge {
  display: inline-block; padding: 1px var(--space-2); border-radius: var(--radius-sm);
  font-size: var(--font-size-xs); font-weight: var(--font-weight-strong); white-space: nowrap;
}
.badge-warning { color: var(--color-red); background: var(--color-red-soft); }

/* Drawer overlay, only used below 768 px */
.drawer-overlay { display: none; }

@media (max-width: 1100px) {
  .search-trigger { min-width: 0; }
  .search-trigger kbd { display: none; }
  .search-trigger .search-text, .user-name {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  .user-button { padding: 0 4px; }
}

@media (max-width: 900px) {
  .record-layout { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 767.98px) {
  .sidebar { transform: translateX(-100%); visibility: hidden; transition: transform .2s ease, visibility 0s linear .2s; }
  .sidebar.is-open { transform: none; visibility: visible; transition: transform .2s ease; }
  .icon-button.sidebar-close { display: grid; margin-left: auto; color: var(--sidebar-text); border-color: var(--sidebar-close-border); background: transparent; }
  .drawer-overlay.is-open { position: fixed; inset: 0; z-index: 25; display: block; background: var(--backdrop); }
  .main { margin-left: 0; }
  .icon-button.menu-button { display: grid; }
  .topbar { padding: var(--space-3) var(--space-4); }
  .eyebrow { display: none; }
  h1 { font-size: var(--font-size-xl); }
  .content { padding: var(--space-4) var(--space-4) var(--space-8); }
  .new-label { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
  .primary-button.new-button { width: 40px; padding: 0; justify-content: center; }
  .details { grid-template-columns: minmax(0, 1fr); }
  .data-table .optional { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .sidebar.is-open { transition: none; }
}

/* Users screen (F02-S04) */
.users-filters { display: flex; flex-wrap: wrap; gap: var(--space-3); font-size: var(--font-size-sm); }
.users-filters > div { display: flex; align-items: center; gap: var(--space-2); }
.users-count { margin: 0 0 var(--space-2); }
.users-filters select, .record-form input[type="text"], .record-form input[type="email"] {
  min-height: 36px; padding: 0 var(--space-2); border: 1px solid var(--color-line); border-radius: var(--radius-sm); background: var(--color-surface);
}
.status-badge { display: inline-block; white-space: nowrap; padding: 2px var(--space-2); border-radius: 999px; font-size: var(--font-size-xs); font-weight: var(--font-weight-strong); }
.status-active { color: var(--color-green); background: var(--color-green-soft); }
.status-invited { color: var(--color-amber); background: var(--color-amber-soft); }
.status-deactivated { color: var(--color-red); background: var(--color-red-soft); }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions .secondary-button { height: 32px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-4); }
.check { display: inline-flex; align-items: center; gap: var(--space-1); margin-right: var(--space-4); font-size: var(--font-size-sm); }
#invite-link { flex: 1; min-width: 0; }
