:root {
  --ink: #17212b;
  --muted: #64717f;
  --line: #dce4ea;
  --panel: #ffffff;
  --page: #eef3f5;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --warn: #b45309;
  --danger: #b91c1c;
  --ok: #15803d;
  --blue: #1d4ed8;
  --shadow: 0 18px 50px rgba(23, 33, 43, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--page);
}

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

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

.sidebar {
  background: #13212b;
  color: #f8fafc;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--accent);
  font-weight: 700;
}

.brand span, .account-card span {
  display: block;
  color: #aebbc7;
  font-size: 13px;
  margin-top: 3px;
}

.nav {
  display: grid;
  gap: 7px;
}

.nav-item {
  border: 0;
  color: #d7e0e8;
  background: transparent;
  text-align: left;
  padding: 12px 14px;
  cursor: pointer;
}

.nav-item.active, .nav-item:hover {
  background: #20323f;
  color: #ffffff;
}

.account-card {
  margin-top: auto;
  padding: 14px;
  border: 1px solid #304453;
  background: #192b37;
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 18px;
}

.topbar p, .panel-head p {
  color: var(--muted);
  margin-top: 4px;
}

.top-actions, .section-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
}

.inline-actions {
  display: flex;
}

.primary-button, .secondary-button {
  border: 0;
  padding: 11px 15px;
  cursor: pointer;
  white-space: nowrap;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.file-button input {
  display: none;
}

.primary-button {
  background: var(--accent);
  color: white;
}

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

.secondary-button {
  background: white;
  color: var(--ink);
  border: 1px solid var(--line);
}

.mini-button {
  padding: 7px 9px;
  font-size: 12px;
}

.danger-button {
  color: var(--danger);
  border-color: #fecaca;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.detail-button {
  width: 100%;
  margin-top: 12px;
}

.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  justify-content: flex-end;
  background: rgba(15, 23, 31, 0.42);
}

.detail-overlay.open {
  display: flex;
}

.detail-drawer {
  width: min(620px, 100%);
  height: 100vh;
  overflow: auto;
  background: #ffffff;
  color: var(--ink);
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 48px rgba(23, 33, 43, 0.18);
  padding: 24px;
  position: relative;
}

.detail-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.detail-header {
  padding-right: 42px;
  margin-bottom: 18px;
}

.detail-kicker {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.detail-header h2 {
  font-size: 24px;
}

.detail-section {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  margin-top: 16px;
}

.detail-section h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

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

.detail-meta div {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  background: #f8fafc;
  padding: 10px 12px;
}

.detail-meta span,
.detail-list small,
.empty-detail {
  color: var(--muted);
}

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

.detail-list article {
  border: 1px solid var(--line);
  background: #fbfcfd;
  padding: 12px;
}

.deficiency-row {
  display: grid;
  gap: 3px;
  border-top: 1px solid var(--line);
  margin-top: 8px;
  padding-top: 8px;
}

.deficiency-row span {
  color: var(--muted);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(15, 23, 31, 0.42);
}

.modal-overlay.open {
  display: flex;
}

.modal-panel {
  width: min(520px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: #ffffff;
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 24px;
  position: relative;
}

.modal-form {
  display: grid;
  gap: 12px;
}

.modal-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.form-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.modal-form input,
.modal-form select,
.modal-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  padding: 11px 12px;
}

.module-check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.module-check-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: #f8fafc;
  padding: 9px 10px;
  color: var(--ink);
}

.module-check-grid input {
  width: auto;
}

.form-status {
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
}

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

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

.modal-actions {
  justify-content: flex-end;
}

.icon-button {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  background: white;
  padding: 10px;
}

.icon-button span {
  display: block;
  height: 2px;
  background: var(--ink);
  margin: 5px 0;
}

.view { display: none; }
.view.active { display: block; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.stat, .panel, .vessel-card, .contact-card, .module-card {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.stat {
  padding: 18px;
}

.stat span, .stat small {
  color: var(--muted);
}

.stat strong {
  display: block;
  font-size: 30px;
  margin: 8px 0 3px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(360px, 0.7fr);
  gap: 16px;
}

.automation-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 0.55fr);
  gap: 16px;
  margin-bottom: 16px;
}

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

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  margin-bottom: 14px;
}

select, input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
}

.sea-map {
  min-height: 430px;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(140deg, rgba(15, 118, 110, 0.22), rgba(29, 78, 216, 0.12)),
    radial-gradient(circle at 72% 28%, rgba(255,255,255,0.45) 0 3px, transparent 4px),
    #b8d7df;
}

.sea-map::before {
  content: "";
  position: absolute;
  inset: 12% 8% 20% 10%;
  background: #d9d0b8;
  clip-path: polygon(4% 28%, 28% 12%, 45% 20%, 58% 5%, 85% 22%, 94% 47%, 73% 68%, 80% 91%, 45% 80%, 25% 95%, 8% 72%);
  opacity: 0.85;
}

.map-label {
  position: absolute;
  color: rgba(23, 33, 43, 0.66);
  font-size: 13px;
  font-weight: 700;
}

.ship-marker {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 3px solid #ffffff;
  background: var(--blue);
  transform: translate(-50%, -50%) rotate(45deg);
  box-shadow: 0 7px 16px rgba(0,0,0,0.22);
  cursor: pointer;
}

.ship-marker.warning { background: var(--warn); }
.ship-marker.ok { background: var(--ok); }

.ship-tip {
  position: absolute;
  min-width: 210px;
  background: #ffffff;
  border: 1px solid var(--line);
  padding: 12px;
  box-shadow: var(--shadow);
  transform: translate(10px, -100%);
  z-index: 4;
}

.mail-list, #inboxList {
  display: grid;
  gap: 10px;
}

.mail-row, .inbox-row {
  border: 1px solid var(--line);
  padding: 12px;
  background: #fbfcfd;
}

.row-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 5px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  padding: 4px 8px;
  font-size: 12px;
  color: var(--muted);
  background: white;
}

.badge.ok { color: var(--ok); border-color: #bbf7d0; }
.badge.warn { color: var(--warn); border-color: #fed7aa; }
.badge.danger { color: var(--danger); border-color: #fecaca; }

.table-wrap {
  overflow: auto;
  background: white;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

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

th {
  color: var(--muted);
  font-size: 13px;
  background: #f8fafc;
}

.section-toolbar {
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-toolbar input {
  max-width: 360px;
}

.section-toolbar select {
  min-width: 220px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  padding: 11px 12px;
}

.login-panel {
  margin-bottom: 14px;
}

.login-test-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 1fr) auto auto;
  gap: 10px;
}

.login-test-form input {
  border: 1px solid var(--line);
  padding: 11px 12px;
}

.cards-grid, .module-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.vessel-card, .contact-card, .module-card {
  padding: 16px;
}

.contact-actions {
  margin-top: 12px;
}

.tank-board {
  background: #24313b;
  color: #f8fafc;
  border: 1px solid #344653;
  box-shadow: var(--shadow);
  padding: 18px;
}

.tank-board-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.tank-board-head h2 {
  text-transform: uppercase;
  letter-spacing: 0;
}

.tank-board-head p {
  color: #b8c5cf;
  margin-top: 4px;
}

.tank-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px;
  color: #dbe7ef;
  font-size: 13px;
}

.legend-dot {
  width: 11px;
  height: 11px;
  display: inline-block;
  border-radius: 50%;
  margin-left: 4px;
}

.legend-dot.ok { background: #63d7a3; }
.legend-dot.warn { background: #f6c343; }
.legend-dot.danger { background: #ff5a67; }

.tank-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 18px 14px;
}

.tank-card {
  --tank-color: #63d7a3;
  min-height: 330px;
  display: grid;
  grid-template-rows: minmax(34px, auto) 1fr auto auto auto;
  justify-items: center;
  gap: 7px;
  padding: 10px 6px;
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(8, 15, 22, 0.16);
}

.tank-card.status-warn { --tank-color: #f6c343; }
.tank-card.status-danger { --tank-color: #ff5a67; }

.tank-card h2 {
  width: 100%;
  color: #edf6ff;
  font-size: 11px;
  text-align: center;
  text-transform: uppercase;
  line-height: 1.25;
}

.tank-meter-wrap {
  display: grid;
  grid-template-columns: 30px 26px;
  align-items: stretch;
  min-height: 210px;
}

.tank-scale {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-end;
  color: #9fb0bd;
  font-size: 10px;
  padding-right: 5px;
  position: relative;
}

.tank-scale::after {
  content: "";
  position: absolute;
  top: 1px;
  right: 0;
  bottom: 1px;
  width: 5px;
  background: repeating-linear-gradient(to bottom, #8fa1ad 0 1px, transparent 1px 10px);
  opacity: 0.8;
}

.tank-tube {
  width: 22px;
  min-height: 210px;
  align-self: stretch;
  display: flex;
  align-items: flex-end;
  background: linear-gradient(90deg, #111b23, #43515a 45%, #1d2932);
  border-left: 1px solid rgba(255,255,255,0.15);
  border-right: 1px solid rgba(0,0,0,0.35);
  overflow: hidden;
}

.tank-fill {
  width: 100%;
  min-height: 2px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--tank-color), #ffffff 26%), var(--tank-color));
  box-shadow: 0 0 16px color-mix(in srgb, var(--tank-color), transparent 35%);
}

.tank-value {
  color: var(--tank-color);
  font-size: 24px;
  line-height: 1;
}

.tank-value small {
  color: #d7e3ec;
  font-size: 12px;
  margin-left: 2px;
}

.tank-name,
.tank-state {
  color: #b8c5cf;
  font-size: 11px;
  text-align: center;
}

.tank-state {
  color: var(--tank-color);
  font-weight: 700;
}

.vessel-subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
  min-height: 18px;
}

.card-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  margin-top: 14px;
  padding-top: 12px;
}

.card-foot b {
  color: var(--ink);
  text-align: right;
}

.meta-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  color: var(--muted);
}

.meta-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.mail-layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.8fr) minmax(0, 1.2fr);
  gap: 16px;
}

.automation-bottom {
  margin-top: 16px;
}

.import-panel {
  margin-bottom: 16px;
}

.import-grid {
  display: grid;
  grid-template-columns: minmax(240px, 0.75fr) minmax(320px, 1.25fr) minmax(240px, 0.8fr);
  gap: 14px;
}

.drop-zone, .paste-box, .import-help {
  border: 1px dashed #b7c4cf;
  background: #fbfcfd;
  padding: 14px;
  min-height: 170px;
}

.drop-zone {
  display: grid;
  align-content: center;
  gap: 10px;
}

.drop-zone span, .paste-box, .import-help {
  color: var(--muted);
}

.paste-box {
  display: grid;
  gap: 8px;
}

.paste-box textarea {
  min-height: 112px;
}

.import-help {
  display: grid;
  align-content: space-between;
  gap: 12px;
}

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

.import-actions button {
  flex: 1;
}

.import-result {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.35;
}

.import-result.ok {
  color: var(--ok);
}

.import-result.warn {
  color: var(--warn);
}

.import-result.danger {
  color: var(--danger);
}

.import-preview,
.import-log-list {
  margin-top: 14px;
}

.preview-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
  color: var(--muted);
}

.preview-head strong {
  color: var(--ink);
}

.preview-table table {
  min-width: 900px;
}

.preview-table small,
.log-item small {
  color: var(--muted);
}

.preview-table .badge {
  white-space: normal;
  line-height: 1.35;
}

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

.log-item {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  background: #fbfcfd;
  padding: 12px;
}

.composer {
  display: grid;
  gap: 13px;
}

.composer label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

textarea {
  min-height: 230px;
  resize: vertical;
  line-height: 1.45;
}

.module-toggle {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-top: 14px;
}

.module-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 14px;
}

.module-card p {
  color: var(--muted);
  line-height: 1.42;
  margin-top: 8px;
}

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

.rule-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border: 1px solid var(--line);
  padding: 13px;
  background: #fbfcfd;
}

.rule-item small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

.ok-text {
  color: var(--ok);
}

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

.mail-settings-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.mail-settings-form .check-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  background: #f8fafc;
  padding: 10px 12px;
}

.mail-settings-form .check-row input {
  width: auto;
}

.mail-settings-form input,
.mail-settings-form select {
  color: var(--ink);
}

.form-note {
  grid-column: 1 / -1;
  color: var(--muted);
  background: #f8fafc;
  border: 1px solid var(--line);
  padding: 10px 12px;
  line-height: 1.4;
}

.form-actions {
  grid-column: 1 / -1;
}

.button-row {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.queue-panel {
  margin-bottom: 16px;
}

.queue-status {
  margin-bottom: 10px;
  color: var(--muted);
  background: #f8fafc;
  border: 1px solid var(--line);
  padding: 10px 12px;
  line-height: 1.35;
}

.queue-status.ok {
  color: var(--ok);
}

.queue-status.danger {
  color: var(--danger);
}

.compact-table table {
  min-width: 840px;
}

.flow-list {
  margin: 16px 0 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.55;
}

.switch {
  width: 48px;
  height: 26px;
  border: 0;
  background: #cbd5e1;
  position: relative;
  cursor: pointer;
}

.switch::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 18px;
  height: 18px;
  background: white;
  transition: transform 0.18s ease;
}

.switch.on {
  background: var(--accent);
}

.switch.on::after {
  transform: translateX(22px);
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: 280px;
  }
  .sidebar.open { transform: translateX(0); }
  .icon-button { display: block; }
  .stats-grid, .cards-grid, .module-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .log-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content-grid, .mail-layout, .automation-grid, .import-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .main { padding: 16px; }
  .topbar { align-items: flex-start; }
  .top-actions { display: none; }
  h1 { font-size: 23px; }
  .stats-grid, .cards-grid, .module-grid { grid-template-columns: 1fr; }
  .log-grid { grid-template-columns: 1fr; }
  .detail-drawer { padding: 18px; }
  .detail-meta { grid-template-columns: 1fr; }
  .mail-settings-form { grid-template-columns: 1fr; }
  .login-test-form { grid-template-columns: 1fr; }
  .module-check-grid { grid-template-columns: 1fr; }
  .panel-head { flex-direction: column; }
  .button-row { justify-content: stretch; }
  .button-row button { flex: 1; }
  .sea-map { min-height: 340px; }
  .section-toolbar { flex-direction: column; align-items: stretch; }
  .section-toolbar input { max-width: none; }
}
