:root {
  color-scheme: dark;
  font-family: "Segoe UI", Arial, sans-serif;
  --ink: #edf7f8;
  --muted: #9fb4bb;
  --line: rgba(126, 177, 188, 0.22);
  --paper: #081114;
  --bg-layer: radial-gradient(circle at 10% 8%, rgba(44, 184, 167, 0.16), transparent 30%),
    radial-gradient(circle at 92% 4%, rgba(82, 137, 226, 0.10), transparent 26%),
    linear-gradient(135deg, #071015 0%, #0b171d 46%, #10151d 100%);
  --panel: rgba(14, 28, 35, 0.92);
  --panel-fade: rgba(12, 27, 34, 0.78);
  --panel-2: rgba(22, 43, 52, 0.88);
  --contact-field-bg: rgba(29, 62, 72, 0.62);
  --field-bg: rgba(8, 21, 27, 0.92);
  --header-bg: rgba(9, 20, 26, 0.88);
  --table-head: rgba(22, 43, 52, 0.96);
  --table-head-text: #c7fbfb;
  --button-secondary: rgba(43, 66, 75, 0.78);
  --button-secondary-text: #e5f5f6;
  --hover-row: rgba(39, 194, 175, 0.13);
  --accent: #39d0bd;
  --accent-dark: #22ad9e;
  --accent-2: #8edff0;
  --danger: #ff6475;
  --soft: rgba(22, 43, 52, 0.88);
  --shadow: rgba(0, 0, 0, 0.34);
  --focus-ring: rgba(57, 208, 189, 0.25);
  --radius: 8px;
  --control-height: 32px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --ink: #102329;
  --muted: #5d7077;
  --line: rgba(99, 135, 145, 0.26);
  --paper: #f0f6f7;
  --bg-layer: radial-gradient(circle at 7% 7%, rgba(39, 194, 175, 0.18), transparent 28%),
    radial-gradient(circle at 96% 3%, rgba(70, 129, 219, 0.12), transparent 28%),
    linear-gradient(135deg, #fbfefe 0%, #edf6f7 50%, #e8f0f2 100%);
  --panel: rgba(255, 255, 255, 0.92);
  --panel-fade: rgba(246, 252, 253, 0.82);
  --panel-2: rgba(238, 248, 249, 0.94);
  --contact-field-bg: rgba(225, 243, 246, 0.96);
  --field-bg: rgba(255, 255, 255, 0.96);
  --header-bg: rgba(247, 252, 253, 0.94);
  --table-head: #e6f4f6;
  --table-head-text: #123943;
  --button-secondary: rgba(218, 235, 238, 0.86);
  --button-secondary-text: #183038;
  --hover-row: rgba(7, 151, 134, 0.10);
  --accent: #079786;
  --accent-dark: #087d71;
  --accent-2: #0f7ea3;
  --danger: #d8344a;
  --soft: #eef7f8;
  --shadow: rgba(16, 35, 42, 0.13);
  --focus-ring: rgba(7, 151, 134, 0.20);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-layer);
  color: var(--ink);
  letter-spacing: 0;
}

h1, h2, h3, p { margin: 0; }

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

button {
  min-height: var(--control-height);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--button-secondary);
  color: var(--button-secondary-text);
  padding: 5px 9px;
  cursor: pointer;
  font-weight: 600;
  line-height: 1.1;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

button:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #041317;
}

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

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px 8px;
  min-height: var(--control-height);
  background: var(--field-bg);
  color: var(--ink);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
  outline: none;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
}

label input,
label textarea,
label select {
  font-weight: 400;
}

.hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg-layer);
}

.login-box {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  background: linear-gradient(180deg, var(--panel), rgba(18, 39, 48, 0.88));
  box-shadow: 0 24px 70px var(--shadow);
  backdrop-filter: blur(18px);
}

.brand-line {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #041317;
  font-weight: 800;
  box-shadow: 0 10px 26px rgba(32, 199, 181, 0.20);
}

.brand-line h1 { font-size: 21px; }
.brand-line p { margin-top: 3px; color: var(--muted); font-size: 13px; }

.error-text {
  min-height: 20px;
  color: var(--danger);
}

.app-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 8px 16px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  backdrop-filter: blur(14px);
}

.topbar .brand-line {
  min-width: 230px;
}

.topbar .brand-line p { color: var(--muted); }

.topbar .brand-mark {
  width: 36px;
  height: 36px;
}

.topbar .brand-line h1 { font-size: 20px; }

.nav {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  padding: 2px 0;
}

.nav button,
.nav a,
.ghost-button {
  min-height: var(--control-height);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 6px 10px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.nav button.active,
.nav button:hover,
.nav a:hover,
.ghost-button:hover {
  border-color: var(--line);
  background: var(--button-secondary);
  color: var(--button-secondary-text);
}

.nav button.active {
  border-color: rgba(57, 208, 189, 0.45);
  color: var(--ink);
}

.panel-tabs {
  flex: 1;
  justify-content: flex-start;
  overflow: visible;
  flex-wrap: wrap;
  gap: 7px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.035);
}

.tab-menu {
  position: relative;
  z-index: 2;
  overflow: visible;
}

.tab-menu.open {
  z-index: 80;
}

.tab-menu > button::after {
  content: "▾";
  margin-left: 6px;
  color: var(--muted);
  font-size: 11px;
}

.tab-menu.open > button {
  border-color: var(--line);
  background: var(--button-secondary);
  color: var(--button-secondary-text);
}

.tab-menu-list {
  position: absolute;
  z-index: 5000;
  top: calc(100% + 6px);
  left: 0;
  min-width: 260px;
  display: none;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px;
  background: var(--panel);
  box-shadow: 0 18px 42px var(--shadow);
}

.tab-menu.open .tab-menu-list,
.tab-menu:focus-within .tab-menu-list {
  display: grid;
}

.tab-menu-list a {
  justify-content: flex-start;
  text-align: left;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.ghost-button { margin-top: 0; }

.top-admin-button {
  border-color: var(--line);
  background: var(--button-secondary);
  color: var(--button-secondary-text);
}

.top-admin-button.active {
  border-color: rgba(57, 208, 189, 0.55);
  background: var(--hover-row);
  color: var(--ink);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.icon {
  width: 30px;
  min-height: 30px;
  padding: 0;
  justify-content: center;
  font-size: 18px;
}

.theme-toggle-btn {
  font-size: 15px;
  line-height: 1;
}

.workspace {
  min-width: 0;
  padding: 18px;
}

.toolbar {
  display: flex;
  gap: 16px;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: 14px;
  padding: 4px 2px;
}

.toolbar h2 { font-size: 26px; font-weight: 750; }
.toolbar p { margin-top: 5px; color: var(--muted); max-width: 820px; }

.searchbar {
  display: flex;
  width: min(560px, 46vw);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--field-bg);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.08);
}

.searchbar input {
  min-width: 0;
  border: 0;
  border-radius: 0;
}

.searchbar button {
  width: 48px;
  border-width: 0 0 0 1px;
  border-radius: 0;
  color: var(--accent);
  font-size: 22px;
}

.panel-head {
  position: relative;
  z-index: 40;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), var(--panel-fade));
  color: var(--muted);
  box-shadow: 0 12px 28px var(--shadow);
  backdrop-filter: blur(14px);
}

.vessel-layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.vessel-sidebar {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 8px;
  height: calc(100vh - 210px);
  min-height: 360px;
}

.vessel-list,
.vessel-details {
  min-height: calc(100vh - 210px);
}

.vessel-list {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 0;
  max-height: none;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px;
  background: linear-gradient(180deg, var(--panel), var(--panel-fade));
  box-shadow: 0 12px 28px var(--shadow);
  backdrop-filter: blur(14px);
}

.vessel-sidebar .vessel-list {
  min-height: 0;
}

.vessel-search {
  width: 100%;
}

.vessel-search input {
  padding-inline: 8px;
}

.vessel-search button {
  width: 38px;
  font-size: 18px;
}

.export-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.export-actions button {
  min-height: 34px;
  border-color: rgba(57, 208, 189, 0.35);
  background: var(--button-secondary);
  color: var(--button-secondary-text);
}

.vessel-list-item {
  width: 100%;
  min-height: 34px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  border-color: transparent;
  background: rgba(255, 255, 255, 0.025);
  text-align: left;
  color: var(--ink);
  padding: 5px 7px;
  font-size: 12px;
}

.vessel-list-item:hover,
.vessel-list-item.active {
  border-color: var(--accent);
  background: var(--hover-row);
}

.vessel-list-item.active {
  color: var(--accent);
  font-weight: 700;
}

.vessel-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: linear-gradient(180deg, var(--panel), var(--panel-fade));
  box-shadow: 0 12px 28px var(--shadow);
  backdrop-filter: blur(14px);
}

.vessel-card-detail {
  min-height: calc(100vh - 210px);
  align-content: start;
}

.vessel-title {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.vessel-title h3 {
  font-size: 22px;
  line-height: 1.25;
}

.vessel-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.vessel-field {
  display: grid;
  align-content: start;
  gap: 4px;
  min-height: 72px;
  padding: 10px 11px;
  border-radius: var(--radius);
  background: var(--panel-2);
  border: 1px solid rgba(126, 177, 188, 0.13);
  overflow-wrap: anywhere;
}

.vessel-field:has(.copy-line[data-kind="email"]),
.vessel-field:has(.copy-line[data-kind="phone"]) {
  background: linear-gradient(180deg, var(--panel-2), var(--contact-field-bg));
}

.copy-line {
  min-height: 28px;
  justify-content: flex-start;
  border-color: transparent;
  background: transparent;
  color: var(--ink);
  padding: 4px 0;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  user-select: text;
}

.copy-line:hover {
  color: var(--accent);
  border-color: transparent;
  box-shadow: none;
}

.copy-line[data-kind="email"],
.copy-line[data-kind="phone"] {
  color: var(--accent-2);
}

.vessel-field b {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.empty-state {
  padding: 14px;
  color: var(--muted);
}

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

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 12px 28px var(--shadow);
}

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

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

th {
  background: var(--table-head);
  color: var(--table-head-text);
}

.section-title {
  display: grid;
  gap: 3px;
  color: var(--ink);
}

.section-title b {
  font-size: 16px;
}

.section-title span {
  color: var(--muted);
  font-size: 12px;
}

.users-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 240px);
  gap: 10px;
  margin-bottom: 12px;
}

.users-search {
  width: 100%;
}

.users-search button {
  font-size: 20px;
}

.users-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.user-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px;
  background: linear-gradient(180deg, var(--panel), var(--panel-fade));
  box-shadow: 0 12px 28px var(--shadow);
}

.user-card.disabled {
  opacity: 0.68;
}

.user-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.user-card h3 {
  font-size: 16px;
  line-height: 1.25;
}

.user-card p,
.user-card-meta {
  color: var(--muted);
  font-size: 13px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 3px 7px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-badge.active {
  border-color: rgba(57, 208, 189, 0.45);
  color: var(--accent);
  background: var(--hover-row);
}

.status-badge.inactive {
  border-color: rgba(255, 91, 107, 0.35);
  color: var(--danger);
  background: rgba(255, 91, 107, 0.09);
}

.user-card-actions {
  display: flex;
  justify-content: flex-end;
}

.dialog-hint {
  padding: 0 14px 12px;
  color: var(--muted);
  font-size: 13px;
}

.dialog-error {
  min-height: 20px;
  padding: 0 14px 10px;
  color: var(--danger);
  font-size: 13px;
}

.password-dialog {
  width: min(520px, 94vw);
}

.password-dialog .dialog-head button {
  display: none;
}

.pages-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
}

.page-form {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--panel);
  box-shadow: 0 12px 28px var(--shadow);
}

dialog {
  width: min(920px, 94vw);
  max-height: 90vh;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 24px 60px var(--shadow);
}

dialog::backdrop { background: rgb(0 0 0 / 0.55); }

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

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

.wide { grid-column: 1 / -1; }

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row input { width: auto; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}

.danger-button {
  margin-right: auto;
  border-color: rgba(255, 91, 107, 0.6);
  background: var(--danger);
  color: #ffffff;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  max-width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 18px 42px var(--shadow);
  font-size: 13px;
}

@media (max-width: 860px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }
  .topbar .brand-line {
    min-width: 0;
  }
  .nav {
    width: 100%;
  }
  .nav button {
    flex: 1 0 auto;
  }
  .top-actions {
    justify-content: flex-start;
  }
  .workspace { padding: 14px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .searchbar { width: 100%; }
  .users-toolbar { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .vessel-layout { grid-template-columns: 1fr; }
  .vessel-fields { grid-template-columns: 1fr; }
  .vessel-sidebar {
    height: auto;
    min-height: auto;
  }
  .vessel-list,
  .vessel-details,
  .vessel-card-detail {
    min-height: auto;
    max-height: none;
  }
}

@media (max-width: 640px) {
  body {
    min-height: 100dvh;
  }

  .topbar {
    gap: 10px;
    padding: 10px;
  }

  .topbar .brand-mark {
    width: 32px;
    height: 32px;
  }

  .topbar .brand-line h1 {
    font-size: 18px;
  }

  .topbar .brand-line p {
    font-size: 12px;
  }

  .nav {
    padding-bottom: 4px;
  }

  .nav button,
  .ghost-button,
  .top-admin-button,
  .theme-toggle-btn {
    min-height: 40px;
  }

  .workspace {
    padding: 10px;
  }

  .toolbar h2 {
    font-size: 20px;
  }

  .toolbar p {
    font-size: 13px;
  }

  .panel-head {
    min-height: auto;
    align-items: stretch;
    flex-direction: column;
    padding: 10px;
  }

  .panel-tabs {
    order: 3;
    width: 100%;
  }

  .tab-menu {
    position: static;
  }

  .tab-menu-list {
    position: static;
    display: none;
    min-width: 100%;
    margin-top: 4px;
  }

  .vessel-sidebar {
    gap: 8px;
  }

  .vessel-list {
    max-height: 34dvh;
  }

  .vessel-list-item {
    min-height: 44px;
    font-size: 14px;
  }

  .vessel-search {
    position: sticky;
    top: 0;
    z-index: 2;
  }

  .vessel-card {
    padding: 10px;
  }

  .vessel-title {
    align-items: stretch;
    flex-direction: column;
  }

  .vessel-fields {
    gap: 8px;
  }

  .vessel-field {
    padding: 10px;
  }

  .copy-line {
    min-height: 42px;
    padding: 7px 0;
    font-size: 15px;
  }

  .toast {
    right: 10px;
    bottom: 10px;
    left: 10px;
    max-width: none;
  }
}
