/* Awego AI Mail OS - Marina Mail Desk (Light Notion-like theme, 0 CDN, 360px+ responsive) */
:root {
  --bg: #fbfbf9;
  --surface: #ffffff;
  --surface-subtle: #f5f4f0;
  --surface-hover: #efede8;
  --border: #e7e5e0;
  --border-strong: #d5d2ca;
  --text: #1f1e1b;
  --text-secondary: #5e5b54;
  --text-muted: #848078;
  --accent: #2364aa;
  --accent-hover: #1b4f8a;
  --accent-soft: #eef4fb;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --danger-border: #fecdca;
  --warn: #9a5b13;
  --warn-bg: #fef9ec;
  --warn-border: #fde68a;
  --ok: #166534;
  --ok-bg: #ecfdf3;
  --ok-border: #bbf7d0;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(24, 24, 21, 0.04);
  --shadow-md: 0 4px 16px rgba(24, 24, 21, 0.08);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
}

/* Top header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(251, 251, 249, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
}

.brand-mark {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--text);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link {
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-link:hover {
  background: var(--surface-subtle);
  color: var(--text);
  text-decoration: none;
}

.nav-link.active {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.user-pill {
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--surface-subtle);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Main container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 18px 16px 36px;
  width: 100%;
  min-width: 0;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.page-title {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.25;
}

.page-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Cards & surfaces */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
  overflow-wrap: anywhere;
}

.card + .card {
  margin-top: 12px;
}

.card-title {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 600;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 22px 0 10px;
}

.section-heading h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

/* KPI grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 14px;
  min-width: 0;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 22px;
  font-weight: 650;
  line-height: 1.2;
}

.kpi-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.kpi-card.kpi-danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.kpi-card.kpi-danger .kpi-value {
  color: var(--danger);
}

/* Alerts & banners */
.banner {
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 14px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  margin-bottom: 14px;
  overflow-wrap: anywhere;
}

.banner-danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

.banner-warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn);
}

.banner-ok {
  background: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text-secondary);
  max-width: 100%;
}

.badge-p0, .badge-danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

.badge-warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn);
}

.badge-ok {
  background: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok);
}

.badge-accent {
  background: var(--accent-soft);
  border-color: #c7ddf5;
  color: var(--accent);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-subtle);
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #ffffff;
}

.btn-ok {
  background: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok);
}

.btn-ok:hover {
  background: #dcfce7;
}

.btn-subtle {
  background: var(--surface-subtle);
  border-color: var(--border);
  color: var(--text-secondary);
}

.btn-sm {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 13px;
}

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

/* Inputs & filters */
.input, .select {
  width: 100%;
  min-height: 38px;
  padding: 7px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s ease;
}

.input:focus, .select:focus {
  border-color: var(--accent);
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
  align-items: center;
}

.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-tab {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.filter-tab:hover {
  background: var(--surface-subtle);
  text-decoration: none;
}

.filter-tab.active {
  background: var(--text);
  border-color: var(--text);
  color: #ffffff;
}

/* Case card */
.case-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  min-width: 0;
}

.case-item.is-p0 {
  border-left: 3px solid var(--danger);
}

.case-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.case-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.case-amount {
  font-weight: 650;
  font-size: 15px;
  white-space: nowrap;
}

.case-title {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.case-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}

.case-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding-top: 8px;
  border-top: 1px solid var(--surface-subtle);
}

.snooze-select {
  width: auto;
  min-height: 32px;
  padding: 3px 8px;
  font-size: 13px;
}

/* Split view (Search & Counterparties) */
.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
  gap: 14px;
  align-items: start;
}

.list-item {
  display: block;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  margin-bottom: 8px;
  color: var(--text);
  transition: border-color 0.12s ease, background 0.12s ease;
  min-width: 0;
  overflow-wrap: anywhere;
}

.list-item:hover {
  border-color: var(--border-strong);
  background: var(--surface-subtle);
  text-decoration: none;
}

.list-item.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.list-item-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}

.list-item-title {
  font-weight: 600;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.list-item-date {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.list-item-sub {
  font-size: 13px;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

.list-item-snippet {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
  overflow-wrap: anywhere;
}

/* Email body & attachments */
.email-body {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.55;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  max-height: 460px;
  overflow-y: auto;
}

.att-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.att-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  min-width: 0;
}

.att-name {
  font-weight: 500;
  font-size: 13px;
  overflow-wrap: anywhere;
  min-width: 0;
  flex: 1 1 180px;
}

/* Ask AI box */
.ask-box {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.ask-form {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.ask-answer {
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
}

/* Tables */
.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th, .data-table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table th {
  background: var(--surface-subtle);
  color: var(--text-secondary);
  font-weight: 600;
  white-space: nowrap;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.mono {
  font-family: var(--font-mono);
  font-size: 12.5px;
}

/* PDF viewer modal */
.pdf-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(20, 20, 18, 0.56);
  display: none;
  flex-direction: column;
  padding: 12px;
}

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

.pdf-dialog {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 980px;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.pdf-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-subtle);
}

.pdf-filename {
  font-weight: 600;
  font-size: 14px;
  overflow-wrap: anywhere;
  min-width: 0;
  flex: 1 1 180px;
}

.pdf-stage {
  flex: 1;
  overflow: auto;
  background: #eae8e2;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.pdf-stage canvas {
  max-width: 100%;
  height: auto !important;
  background: #ffffff;
  box-shadow: var(--shadow-md);
  border-radius: 4px;
}

.pdf-stage img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  box-shadow: var(--shadow-md);
}

.pdf-text-view {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13.5px;
  line-height: 1.55;
}

/* Login screen */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
}

.login-card {
  max-width: 420px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px 20px;
  box-shadow: var(--shadow-md);
}

.login-card h1 {
  margin: 12px 0 8px;
  font-size: 20px;
  font-weight: 650;
}

.login-card p {
  margin: 0 0 12px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* Toast notification */
.toast {
  position: fixed;
  right: 16px;
  bottom: 76px;
  z-index: 100;
  background: var(--text);
  color: #ffffff;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  box-shadow: var(--shadow-md);
  max-width: calc(100vw - 32px);
  display: none;
}

.toast.show {
  display: block;
}

/* Mobile bottom nav */
.bottom-nav {
  display: none;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-secondary);
  font-size: 13px;
}

.empty-state {
  text-align: center;
  padding: 24px 14px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* Mobile & Telegram Mini App (360px - 430px) */
@media (max-width: 900px) {
  .split-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 768px) {
  .nav-links {
    display: none;
  }

  .container {
    padding: 14px 12px 84px;
  }

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

  .kpi-value {
    font-size: 19px;
  }

  .page-title {
    font-size: 19px;
  }

  .ask-form {
    flex-direction: column;
  }

  .pdf-modal {
    padding: 0;
  }

  .pdf-dialog {
    border-radius: 0;
  }

  .bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  }

  .bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 5px 2px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .bottom-nav a.active {
    color: var(--accent);
    background: var(--accent-soft);
    font-weight: 600;
  }
}
