:root {
  color-scheme: light;
  --background: #f6f7f9;
  --panel: #ffffff;
  --text: #172026;
  --muted: #667085;
  --line: #d9dee7;
  --accent: #1f6feb;
  --accent-hover: #195cc5;
  --success-bg: #e8f5ee;
  --success-text: #156f45;
  --warn-bg: #fff2d9;
  --warn-text: #875300;
  --danger-bg: #fde7e7;
  --danger-text: #a41919;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--background);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.2rem;
  line-height: 1.08;
}

h2 {
  margin-bottom: 6px;
  font-size: 1.12rem;
  line-height: 1.25;
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-panel,
.entry-panel,
.list-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 28px rgb(23 32 38 / 7%);
}

.auth-panel {
  width: min(100%, 420px);
  padding: 24px;
}

.app-frame {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.app-sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
  min-height: 100vh;
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  background: #ffffff;
}

.sidebar-brand {
  padding: 8px 8px 18px;
  border-bottom: 1px solid var(--line);
}

.sidebar-main {
  display: grid;
  gap: 18px;
}

.sidebar-menu {
  display: grid;
  gap: 6px;
}

.sidebar-footer {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 14px 8px 0;
}

.session-user {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-content {
  min-width: 0;
  padding: 24px clamp(18px, 4vw, 40px) 48px;
}

.tab-button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-height: 40px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.tab-button.active,
.tab-button:hover {
  background: #edf4ff;
  color: #114a9f;
}

.workspace-grid,
.admin-grid,
.employees-grid,
.todos-grid {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
  gap: 24px;
}

.companies-layout,
.employees-layout,
.todos-layout,
.emails-layout {
  display: grid;
  gap: 24px;
}

.entry-panel,
.list-panel {
  min-width: 0;
  padding: 24px;
}

.entry-panel {
  align-self: start;
}

.section-heading p {
  margin-bottom: 0;
  color: var(--muted);
}

.row-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

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

.list-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.mailbox-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.mailbox-tabs .active-filter {
  border-color: #aac8f7;
  background: #edf4ff;
  color: #114a9f;
}

.stacked-form {
  display: grid;
  gap: 16px;
  margin-top: 18px;
}

.divided {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #c7cfdb;
  border-radius: 6px;
  padding: 9px 11px;
  color: var(--text);
  background: #ffffff;
  outline: none;
}

textarea {
  min-height: 92px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(31 111 235 / 14%);
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 14px;
}

.form-grid.compact {
  grid-template-columns: 110px minmax(0, 1fr);
}

.form-grid.equal {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

body.modal-open {
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: 22px;
  background: rgb(23 32 38 / 42%);
}

.modal-panel {
  width: min(100%, 580px);
  max-height: calc(100vh - 44px);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: var(--panel);
  box-shadow: 0 18px 48px rgb(23 32 38 / 20%);
}

.modal-panel.detail-modal {
  width: min(100%, 820px);
}

.inline-form-panel {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 720;
  cursor: pointer;
}

button:hover {
  background: var(--accent-hover);
}

button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
}

.secondary-button:hover {
  background: #f1f4f8;
}

.sidebar-footer .secondary-button {
  width: 100%;
  justify-content: center;
}

.compact-button {
  min-height: 34px;
  padding: 0 12px;
}

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

.note-panel {
  display: grid;
  gap: 16px;
}

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

.note-item,
.todo-history-item,
.email-history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f9fafb;
}

.note-meta {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.note-text {
  margin-bottom: 0;
  white-space: pre-wrap;
}

.todo-history-list {
  display: grid;
  gap: 10px;
}

.email-history-list {
  display: grid;
  gap: 10px;
}

.todo-history-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.todo-history-text {
  margin-bottom: 8px;
  white-space: pre-wrap;
}

.todo-history-details {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.email-history-subject {
  margin-bottom: 8px;
  font-weight: 760;
}

.email-history-details {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.email-history-body {
  margin-bottom: 0;
  white-space: pre-wrap;
}

.email-detail h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
  line-height: 1.3;
}

.email-detail .email-history-body {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.email-subject-cell {
  max-width: 320px;
}

.email-preview {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.todo-history-action {
  display: flex;
  align-items: center;
  margin-top: 10px;
}

.empty-inline {
  margin-bottom: 0;
  color: var(--muted);
}

.form-status {
  min-height: 22px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.35;
}

.form-status.success {
  color: var(--success-text);
}

.form-status.error {
  color: var(--danger-text);
}

.table-wrap {
  position: relative;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  background: #ffffff;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: #475467;
  background: #f9fafb;
  font-size: 0.8rem;
  font-weight: 760;
  text-transform: uppercase;
}

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

.strong {
  font-weight: 760;
}

.muted {
  color: var(--muted);
}

.notes-cell {
  max-width: 260px;
  color: var(--muted);
  white-space: pre-wrap;
}

.todo-text-cell {
  max-width: 340px;
  white-space: pre-wrap;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.82rem;
  font-weight: 760;
  white-space: nowrap;
}

.status-ok {
  background: var(--success-bg);
  color: var(--success-text);
}

.status-warning {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.status-error {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.empty-state {
  padding: 32px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 980px) {
  .app-frame {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .workspace-grid,
  .admin-grid,
  .employees-grid,
  .companies-layout,
  .employees-layout,
  .emails-layout,
  .todos-layout,
  .todos-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-frame {
    grid-template-columns: 1fr;
  }

  .app-sidebar {
    position: static;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar-main {
    gap: 14px;
  }

  .sidebar-menu {
    grid-template-columns: 1fr 1fr;
  }

  .sidebar-footer {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    padding-top: 12px;
  }

  .row-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .entry-panel,
  .list-panel,
  .auth-panel {
    padding: 18px;
  }

  .form-grid,
  .form-grid.compact,
  .form-grid.equal,
  .list-controls,
  .form-actions {
    grid-template-columns: 1fr;
  }

  .header-actions {
    justify-content: stretch;
  }

  .header-actions button {
    width: 100%;
  }

  .modal-backdrop {
    align-items: start;
    padding: 12px;
  }

  .modal-panel {
    max-height: calc(100vh - 24px);
    padding: 18px;
  }
}
