:root {
  --bg: #dce4ee;
  --ink: #0f1a28;
  --muted: #4c6076;
  --line: #bcc9d8;
  --surface: #edf2f8;
  --surface-2: #e4ecf5;
  --accent: #005f9f;
  --accent-soft: #c7dff3;
  --item: #e8eff7;
  --item-active: #d9e8f6;
  --shadow: 0 14px 34px rgba(10, 31, 52, 0.14);
  --pane-size: 360px;
  --pane-size-v: 320px;
}

* {
  box-sizing: border-box;
}

body[data-theme="dark"] {
  --bg: #0e1620;
  --ink: #f3f8ff;
  --muted: #c2d2e4;
  --line: #3f5268;
  --surface: #1a2a3b;
  --surface-2: #142334;
  --accent: #8bcaf8;
  --accent-soft: #20415c;
  --item: #203145;
  --item-active: #27415a;
  --shadow: 0 16px 36px rgba(0, 0, 0, 0.4);
}

body[data-theme="dark"][data-contrast="high"] {
  --ink: #ffffff;
  --muted: #d7e7f6;
  --line: #5f7d9b;
  --accent: #a8dcff;
  --accent-soft: #2b5577;
  --item: #22384d;
  --item-active: #2e4f6c;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Noto Sans", sans-serif;
  background:
    radial-gradient(900px 420px at 85% -5%, rgba(0, 95, 159, 0.2), transparent 55%),
    linear-gradient(160deg, var(--bg), #c9d5e3 55%, #b8c6d7);
  color: var(--ink);
  min-height: 100vh;
  font-size: 16px;
  overflow: hidden;
}

body.tab-admin-active {
  overflow: auto;
}

body.is-busy .app {
  pointer-events: none;
}

.app {
  width: calc(100vw - 20px);
  margin: 10px;
  padding: 0 10px 10px;
  height: calc(100vh - 20px);
  display: flex;
  flex-direction: column;
}

body.tab-admin-active .app {
  height: auto;
  min-height: calc(100vh - 20px);
}

.busy-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 14, 22, 0.42);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  z-index: 9999;
}

.busy-overlay[hidden] {
  display: none !important;
}

.busy-card {
  min-width: 300px;
  max-width: 420px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, var(--surface), var(--surface-2));
  color: var(--ink);
  box-shadow: var(--shadow);
}

.busy-card p {
  margin: 0 0 8px;
  font-weight: 600;
}

.progress-track {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line) 65%, transparent);
  overflow: hidden;
}

.progress-indeterminate {
  height: 100%;
  width: 34%;
  border-radius: 999px;
  background: var(--accent);
  animation: progress-indeterminate 1.2s ease-in-out infinite;
}

@keyframes progress-indeterminate {
  0% { transform: translateX(-130%); }
  50% { transform: translateX(90%); }
  100% { transform: translateX(300%); }
}


.topbar {
  margin-bottom: 14px;
  position: relative;
  background: linear-gradient(150deg, var(--surface), var(--surface-2));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 16px 14px;
  box-shadow: var(--shadow);
}

.topbar h1 {
  margin: 0;
  font-size: 1.52rem;
  letter-spacing: 0.2px;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.topbar-actions {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.topbar-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.82rem;
  font-weight: 600;
}

.topbar-control select {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 3px 6px;
  min-width: 64px;
  font: inherit;
}

.status-pill {
  display: inline-block;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.82rem;
  font-weight: 600;
}

.secondary-btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
  font-weight: 600;
}

.link-btn {
  display: inline-block;
  text-decoration: none;
}

.secondary-btn.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.theme-toggle {
  position: absolute;
  right: 14px;
  top: 14px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 120ms ease, border-color 120ms ease;
}

.theme-toggle:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.toolbar {
  display: flex;
  gap: 12px;
  margin: 12px 0 10px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}

.toolbar label {
  color: var(--muted);
  font-size: 0.9rem;
}

.toolbar select {
  display: block;
  margin-top: 4px;
  min-width: 190px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink);
}

.toolbar input,
.form-grid input,
.form-grid select {
  display: block;
  margin-top: 4px;
  width: 100%;
  min-width: 170px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink);
}

.tabs {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  overflow: hidden;
  padding: 4px;
  box-shadow: var(--shadow);
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 600;
  border-radius: 999px;
  transition: background 120ms ease, color 120ms ease;
}

.tab.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.panel {
  display: none;
  margin-top: 12px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.panel.is-active {
  display: flex;
  flex-direction: column;
}

#tab-admin {
  overflow: visible;
  gap: 10px;
}

.admin-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  flex: 0 0 auto;
  min-height: auto;
  overflow: visible;
}

#tab-admin .admin-layout .detail {
  height: auto;
  min-height: 0;
}

#tab-admin > .detail {
  height: auto;
  min-height: 0;
}

#admin-dashboard {
  margin-bottom: 0;
}

#admin-laptop-files {
  margin-bottom: 0;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.stats-table th,
.stats-table td {
  border-bottom: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
}

.mail-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.folders-pane {
  background: linear-gradient(160deg, var(--surface), var(--surface-2));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  box-shadow: var(--shadow);
  overflow: auto;
}

.folders-pane h3 {
  margin: 4px 6px 8px;
  font-size: 0.92rem;
  color: var(--muted);
}

.folder-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--item);
  color: var(--ink);
  padding: 8px;
  margin-bottom: 6px;
  cursor: pointer;
}

.folder-item.is-active,
.folder-item:hover {
  border-color: var(--accent);
  background: var(--item-active);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-grid label {
  color: var(--muted);
  font-size: 0.9rem;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  margin-top: 8px;
}

.split {
  display: grid;
  grid-template-columns: var(--pane-size) 12px 1fr;
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.list,
.detail {
  background: linear-gradient(160deg, var(--surface), var(--surface-2));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  box-shadow: var(--shadow);
  min-height: 0;
  height: 100%;
  overflow: auto;
}

.detail.html-rich-mode {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail.html-rich-mode h2,
.detail.html-rich-mode .meta,
.detail.html-rich-mode .toolbar,
.detail.html-rich-mode .attachments {
  flex: 0 0 auto;
}

.mail-body-host-html {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

.mail-body-host-text {
  flex: 0 0 auto;
}

.mail-html-frame {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}

.resizer {
  width: 2px;
  margin: 0 auto;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent-soft) 80%, transparent);
  cursor: col-resize;
  position: relative;
}

.resizer::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 36px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent-soft) 45%, transparent);
  opacity: 0;
  transition: opacity 120ms ease;
}

.resizer:hover::after {
  opacity: 1;
}

.split.vertical {
  grid-template-columns: 1fr;
  grid-template-rows: var(--pane-size-v) 12px 1fr;
}

.split.vertical .resizer {
  height: 2px;
  margin: auto 0;
  width: 100%;
  cursor: row-resize;
}

.split.vertical .resizer::after {
  width: 36px;
  height: 14px;
}

.item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--item);
  padding: 7px 9px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.item:hover,
.item.is-active {
  border-color: var(--accent);
  background: var(--item-active);
  transform: translateY(-1px);
}

.item.unread {
  border-left: 3px solid var(--accent);
}

.item.unread .item-title {
  font-weight: 700;
}

.item-title {
  font-weight: 600;
  margin: 0 0 2px;
}

.pager-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 8px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface-2) 90%, transparent);
}

.pager-row .secondary-btn[disabled] {
  opacity: 0.5;
  cursor: default;
}

.item-sub {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.compact-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.compact-sub {
  line-height: 1.2;
}

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

h2 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 1.3rem;
}

.meta {
  margin: 0 0 12px;
  color: var(--muted);
}

.compact-meta {
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.pre {
  white-space: pre-wrap;
  line-height: 1.35;
  font-size: 0.95rem;
}

.pre a {
  color: var(--accent);
  text-decoration: underline;
}

.attachments {
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface-2) 85%, transparent);
  padding: 8px;
  margin-bottom: 8px;
}

.attachments h3 {
  margin: 0 0 6px;
  font-size: 0.95rem;
}

.attachments ul {
  margin: 0;
  padding-left: 16px;
}

.attachments li {
  margin: 2px 0;
  font-size: 0.9rem;
}

.calendar-day-block {
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: color-mix(in srgb, var(--surface-2) 88%, transparent);
}

.calendar-day-block h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  color: var(--muted);
}

.calendar-month-grid {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.calendar-month-grid th,
.calendar-month-grid td {
  border: 1px solid var(--line);
  padding: 6px;
  vertical-align: top;
}

.calendar-month-grid td {
  cursor: pointer;
  min-height: 62px;
}

.calendar-month-grid td.out-month {
  opacity: 0.55;
}

.calendar-month-grid .day-num {
  font-weight: 700;
  margin-bottom: 4px;
}

@media (max-width: 900px) {
  .theme-toggle {
    position: static;
    margin-top: 10px;
  }

  .toolbar {
    flex-direction: column;
  }

  .split {
    grid-template-columns: 1fr;
  }

  .resizer {
    display: none;
  }

  .mail-layout,
  .admin-layout,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .list,
  .detail {
    min-height: auto;
  }
}
