:root {
  --bg: #e8eef2;
  --bg-panel: #f7fafc;
  --bg-header: #1c2b36;
  --ink: #1a242d;
  --ink-muted: #5c6b78;
  --line: #c5d0d8;
  --line-strong: #9aadb8;
  --accent: #0d6e6e;
  --accent-hover: #0a5858;
  --accent-soft: #d7ecec;
  --danger: #a33b3b;
  --danger-hover: #872f2f;
  --row-hover: #eef5f5;
  --row-selected: #d4e8e8;
  --shadow: 0 10px 30px rgba(28, 43, 54, 0.18);
  --radius: 6px;
  --font: "DM Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --left-width: 42%;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(13, 110, 110, 0.12), transparent 55%),
    radial-gradient(900px 400px at 90% 0%, rgba(28, 43, 54, 0.08), transparent 50%),
    var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.app-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.login-screen {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  min-height: 100%;
}

.login-card {
  width: min(100%, 380px);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 1.5rem 1.4rem 1.35rem;
  display: grid;
  gap: 0.9rem;
}

.login-card > form {
  display: grid;
  gap: 0.9rem;
}

.login-title {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 700;
}

.login-subtitle {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.95rem;
}

.login-help {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.88rem;
  line-height: 1.4;
  font-weight: 400;
}

.login-links {
  margin: 0;
  text-align: center;
}

.link-btn {
  border: 0;
  background: transparent;
  color: var(--accent, #2f6fed);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  text-decoration: underline;
  text-underline-offset: 0.12em;
}

.link-btn:hover {
  color: var(--ink);
}

.form-success {
  margin: 0;
  color: #1f7a45;
  font-size: 0.88rem;
}

.password-field {
  position: relative;
  display: flex;
  align-items: center;
}

.password-field input {
  width: 100%;
  padding-right: 2.6rem;
}

.password-toggle {
  position: absolute;
  right: 0.35rem;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: 4px;
}

.password-toggle:hover {
  color: var(--ink);
  background: rgba(28, 43, 54, 0.06);
}

.password-toggle svg {
  width: 1.15rem;
  height: 1.15rem;
}

.login-submit {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.6rem 0.9rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  background: linear-gradient(180deg, #243746 0%, var(--bg-header) 100%);
  color: #f2f6f8;
  border-bottom: 1px solid #101820;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 1.05rem;
  min-width: 0;
}

.brand-logo {
  width: 2.35rem;
  height: 2.35rem;
  flex: 0 0 auto;
  object-fit: contain;
  border-radius: 6px;
  display: block;
}

.brand-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  flex: 1;
  justify-content: flex-end;
}

.session-item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.session .label {
  color: #9fb1be;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.7rem;
}

.session .value {
  color: #fff;
  font-weight: 500;
}

.logout-btn {
  margin-left: 0.25rem;
  flex: 0 0 auto;
  width: 2.35rem;
  height: 2.35rem;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: #e8eef2;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.4);
  color: #fff;
}

.logout-btn svg {
  width: 1.2rem;
  height: 1.2rem;
}

.split-layout {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-height: 0;
  padding: 0.85rem;
  gap: 0;
}

.pane {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 220px;
  min-height: 0;
  overflow: hidden;
}

.pane-left {
  width: var(--left-width);
  flex: 0 0 auto;
  border-radius: var(--radius) 0 0 var(--radius);
}

.pane-right {
  flex: 1 1 auto;
  border-radius: 0 var(--radius) var(--radius) 0;
  border-left: none;
}

.splitter {
  width: 6px;
  flex: 0 0 6px;
  cursor: col-resize;
  background: linear-gradient(180deg, #d5dee5, #b7c5cf);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  position: relative;
  touch-action: none;
}

.splitter::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 36px;
  transform: translate(-50%, -50%);
  border-radius: 2px;
  background: var(--line-strong);
}

.splitter:hover,
.splitter:focus-visible,
body.resizing .splitter {
  background: #9fc2c2;
  outline: none;
}

.pane-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
}

.pane-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
}

.search-field {
  flex: 1;
  max-width: 260px;
}

.search-field input,
.field input,
.field textarea,
.cell-input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 0.45rem 0.65rem;
  font: inherit;
  background: #fff;
  color: var(--ink);
}

.search-field input:focus,
.field input:focus,
.field textarea:focus,
.cell-input:focus {
  outline: 2px solid rgba(13, 110, 110, 0.35);
  border-color: var(--accent);
}

.field textarea,
.cell-note {
  resize: vertical;
  min-height: 2.5rem;
}

.field input:disabled,
.field input:read-only,
.field textarea:disabled {
  background: #eef2f5;
  color: var(--ink);
  opacity: 1;
}

.table-wrap {
  flex: 1;
  overflow: auto;
  min-height: 0;
  position: relative;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.data-table th,
.data-table td {
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table thead {
  position: sticky;
  top: 0;
  background: #eef3f6;
  z-index: 1;
}

.data-table th {
  font-weight: 600;
  color: var(--ink-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.contacts-table {
  table-layout: fixed;
}

.contacts-col-name {
  width: 28%;
}

.contacts-col-email {
  width: 32%;
}

.contacts-col-notes {
  width: auto;
}

.contacts-th-name {
  position: relative;
}

.col-resizer {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 2;
  touch-action: none;
  user-select: none;
}

.col-resizer::after {
  content: "";
  position: absolute;
  top: 0.35rem;
  bottom: 0.35rem;
  left: 2px;
  width: 2px;
  border-radius: 1px;
  background: transparent;
  transition: background 0.12s ease;
}

.col-resizer:hover::after,
.col-resizer:focus-visible::after,
body.col-resizing .col-resizer::after {
  background: var(--accent, #3d6f8f);
}

body.col-resizing {
  cursor: col-resize !important;
  user-select: none;
}

body.col-resizing * {
  cursor: col-resize !important;
}

.col-active {
  width: 5.5rem;
}

.col-row-actions {
  width: 4.5rem;
}

.field-check {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  justify-content: flex-end;
}

.field-check input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
}

.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.sort-btn:hover {
  color: var(--ink);
}

.sort-indicator::after {
  content: "↕";
  opacity: 0.35;
  font-size: 0.75rem;
}

.sort-indicator.asc::after {
  content: "▲";
  opacity: 1;
  color: var(--accent);
}

.sort-indicator.desc::after {
  content: "▼";
  opacity: 1;
  color: var(--accent);
}

.data-table tbody tr {
  transition: background 0.12s ease;
}

.pane-left .data-table tbody tr {
  cursor: pointer;
}

.data-table tbody tr:hover {
  background: var(--row-hover);
}

.pane-left .data-table tbody tr.selected {
  background: var(--row-selected);
}

.pane-left .data-table tbody tr.selected td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}

.pane-left .data-table tbody tr.contact-drop-target {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: #e4f3f3;
}

.contact-row {
  cursor: grab;
}

.contact-row.contact-dragging {
  opacity: 0.55;
  cursor: grabbing;
}

body.dragging-contact {
  cursor: grabbing;
}

body.dragging-contact .pane-left .data-table tbody tr {
  cursor: copy;
}

.active-check {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.empty-state {
  margin: 2rem 1rem;
  text-align: center;
  color: var(--ink-muted);
}

.pane-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.65);
}

.actions-left,
.actions-right {
  display: flex;
  gap: 0.5rem;
}

.btn {
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0.45rem 0.9rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-toggle.is-pressed,
.btn-toggle[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: #fff;
  border-color: var(--line-strong);
  color: var(--ink);
}

.btn-secondary:hover:not(:disabled) {
  background: #eef3f6;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-tiny {
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
}

.right-empty,
.right-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.right-empty {
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.subtabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  padding: 0 0.75rem;
}

.subtab {
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  font: inherit;
  font-weight: 600;
  padding: 0.85rem 1rem 0.75rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.subtab:hover {
  color: var(--ink);
}

.subtab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.subtab-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.info-form {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 1.1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-width: 42rem;
  width: 100%;
}

.info-fields {
  display: grid;
  gap: 0.85rem;
  flex: 0 0 auto;
}

.field-background {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: stretch;
}

.field-background > span {
  flex: 0 0 auto;
}

.field-background textarea {
  flex: 1 1 auto;
  min-height: 0;
  align-self: stretch;
  resize: none;
  overflow: auto;
  font: inherit;
  line-height: 1.4;
}

.subtab-actions {
  margin-top: auto;
}

.interactions-wrap {
  padding-bottom: 0;
}

.interactions-table .cell-input {
  min-width: 7rem;
}

.interactions-table .cell-note {
  min-width: 12rem;
}

.doc-action {
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-download {
  color: var(--accent);
  text-decoration: underline;
}

.doc-upload {
  color: var(--ink-muted);
}

.doc-upload:hover,
.doc-download:hover {
  color: var(--accent-hover);
}

.muted {
  color: var(--ink-muted);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 32, 0.45);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 50;
}

#confirmOverlay {
  z-index: 60;
}

.modal {
  width: min(100%, 400px);
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 1.25rem 1.35rem 1.15rem;
  border: 1px solid var(--line);
  animation: pop 0.16s ease-out;
}

.modal-wide {
  width: min(100%, 560px);
}

.detail-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem 1rem;
}

.detail-form .field-full {
  grid-column: 1 / -1;
}

.interactions-table tbody tr {
  cursor: pointer;
}

.interactions-table tbody tr.selected {
  background: var(--row-selected);
}

.interactions-table:focus {
  outline: none;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.modal-title {
  margin: 0 0 1rem;
  font-size: 1.15rem;
}

.field {
  display: grid;
  gap: 0.4rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.field.field-background {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-error {
  margin: 0.75rem 0 0;
  color: var(--danger);
  font-size: 0.88rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.15rem;
}

.modal-actions-left {
  justify-content: flex-start;
  grid-column: 1 / -1;
}

.modal-actions-split {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.15rem;
  grid-column: 1 / -1;
}

.modal-actions-left-group {
  display: flex;
  gap: 0.5rem;
}

.modal-confirm {
  width: min(100%, 380px);
}

.confirm-message {
  margin: 0;
  font-size: 1rem;
  line-height: 1.45;
}

body.resizing {
  cursor: col-resize;
  user-select: none;
}

body.resizing iframe,
body.resizing * {
  cursor: col-resize !important;
}

@media (max-width: 720px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .pane {
    min-width: 140px;
  }
}
