/* ====================================================================
 * Aviveil Owner Console Stylesheet (css/owner.css)
 * Strictly follows Aviveil Design System (aviveil-design-system.md)
 * & CRM Management Design Screenshots
 * ==================================================================== */

:root {
  --bg: #16171b;
  --p: #1e2025;
  --p2: #262930;
  --ln: #33363f;
  --tx: #e6e4ea;
  --mu: #8f93a0;
  --a: #c9b6e4;   /* accent purple */
  --b: #a9d3e0;   /* blue: future / contracted */
  --g: #b5dcc3;   /* green: good, paid, profit */
  --r: #eab5c0;   /* pink: risk, overdue, negative */
  --y: #efdcb0;   /* yellow: watch, target line */
}

[data-theme="light"] {
  --bg: #f6f4f8;
  --p: #ffffff;
  --p2: #efecf3;
  --ln: #dedae5;
  --tx: #2b2a33;
  --mu: #777585;
  --a: #8f72c4;
  --b: #4f9bb3;
  --g: #4fa377;
  --r: #d6687d;
  --y: #b98b2a;
}

/* Root Console Layout */
.owner-console {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 26px 26px 104px;
  box-sizing: border-box;
  font-family: "Inter Tight", "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: var(--tx);
  background: var(--bg);
  min-width: 0;
  line-height: 1.5;
}

/* 1. Page Header: title (20px, 500) on left, small muted meta (12px) on right */
.owner-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 12px;
  gap: 12px;
}

.owner-title-group {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  width: 100%;
  gap: 12px;
}

.owner-page-title {
  font-size: 20px;
  font-weight: 500;
  color: var(--tx);
  margin: 0;
  line-height: 1.2;
}

.owner-meta-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.owner-timestamp {
  font-size: 12px;
  color: var(--mu);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

/* 2. Underline Tabs: strictly horizontal menu bar directly under title */
.owner-tabs-nav,
nav.owner-tabs-nav {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: flex-start !important;
  gap: 24px !important;
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
  min-height: 0 !important;
  border-top: none !important;
  border-left: none !important;
  border-right: none !important;
  border-bottom: 1px solid var(--ln) !important;
  margin: 0 0 16px 0 !important;
  background: transparent !important;
  padding: 0 !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  position: static !important;
  transform: none !important;
  box-shadow: none !important;
  z-index: auto !important;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.owner-tabs-nav::-webkit-scrollbar,
nav.owner-tabs-nav::-webkit-scrollbar {
  display: none;
}

.owner-tab-item,
nav.owner-tabs-nav .owner-tab-item {
  background: none !important;
  border: none !important;
  padding: 6px 0 12px !important;
  font-family: inherit !important;
  font-size: 13.5px !important;
  font-weight: 400 !important;
  color: var(--mu) !important;
  cursor: pointer !important;
  position: relative !important;
  white-space: nowrap !important;
  transition: color 150ms ease !important;
  outline: none !important;
  display: inline-block !important;
  text-decoration: none !important;
  min-height: 0 !important;
  border-radius: 0 !important;
}

.owner-tab-item:hover,
nav.owner-tabs-nav .owner-tab-item:hover {
  color: var(--tx) !important;
  background: none !important;
}

.owner-tab-item:focus-visible,
nav.owner-tabs-nav .owner-tab-item:focus-visible {
  outline: 2px solid var(--a) !important;
  outline-offset: 2px !important;
}

.owner-tab-item.active,
nav.owner-tabs-nav .owner-tab-item.active {
  color: var(--tx) !important;
  background: none !important;
  font-weight: 500 !important;
}

.owner-tab-item.active::after,
nav.owner-tabs-nav .owner-tab-item.active::after {
  content: '' !important;
  position: absolute !important;
  bottom: -1px !important;
  left: 0 !important;
  right: 0 !important;
  height: 2px !important;
  background: var(--a) !important;
}

/* 3. Controls & Filter Bar */
.owner-controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

/* Segmented control: joined buttons in a 1px bordered pill (radius 10) */
.owner-range-segmented {
  display: inline-flex;
  align-items: center;
  background: transparent;
  border: 1px solid var(--ln);
  border-radius: 10px;
  padding: 2px;
  gap: 2px;
}

.owner-range-pill {
  background: transparent;
  border: none;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 400;
  color: var(--mu);
  border-radius: 8px;
  cursor: pointer;
  transition: color 150ms ease, background 150ms ease;
  white-space: nowrap;
  outline: none;
}

.owner-range-pill:hover {
  color: var(--tx);
}

.owner-range-pill:focus-visible {
  outline: 2px solid var(--a);
}

.owner-range-pill.active {
  background: var(--p2);
  color: var(--tx);
}

.owner-filter-dropdowns {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Selects: height 34, radius 8, panel-2 background, 1px --ln */
.owner-select {
  height: 34px;
  background-color: var(--p2);
  border: 1px solid var(--ln);
  border-radius: 8px;
  padding: 0 28px 0 12px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 400;
  color: var(--tx);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--mu) 50%), linear-gradient(135deg, var(--mu) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  outline: none;
  transition: border-color 150ms ease;
}

.owner-select:hover {
  border-color: var(--a);
}

.owner-select:focus {
  border-color: var(--a);
  outline: 2px solid rgba(201, 182, 228, 0.4);
}

/* 4. Executive Summary Sentence */
.crm-summary-lead {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.crm-summary-bold {
  font-size: 15px;
  font-weight: 400;
  color: var(--tx);
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

.crm-summary-sub {
  font-size: 13px;
  font-weight: 400;
  color: var(--mu);
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

/* 5. Card: background var(--p); border 1px var(--ln); border-radius 12px; padding 20 */
.crm-card {
  background: var(--p);
  border: 1px solid var(--ln);
  border-radius: 12px;
  padding: 20px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
}

/* Card heading: 12px, --mu, weight 400, margin-bottom 12 */
.crm-card-heading {
  font-size: 12px;
  font-weight: 400;
  color: var(--mu);
  margin: 0 0 12px 0;
  line-height: 1.3;
}

/* Hero number: 36px, weight 300, letter-spacing -0.02em, line-height 1.1 */
.crm-hero-num {
  font-size: 36px;
  font-weight: 300;
  color: var(--tx);
  line-height: 1.1;
  margin: 0 0 6px 0;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.crm-hero-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.crm-hero-sub {
  font-size: 12px;
  font-weight: 400;
  color: var(--mu);
  font-variant-numeric: tabular-nums;
  margin: 0;
}

/* 6. Grid Layouts: 14px gap */
.crm-hero-grid,
.crm-two-col {
  display: grid;
  grid-template-columns: 2.2fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.crm-full-row {
  margin-bottom: 14px;
}

.crm-key-strip-6 {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.crm-key-strip-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.crm-two-col-equal {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.crm-three-col {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

/* 7. Key Figure (KPI) Cards */
.crm-kf-card {
  background: var(--p);
  border: 1px solid var(--ln);
  border-radius: 12px;
  padding: 20px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  min-height: 100px;
}

.crm-kf-card .crm-card-heading {
  margin-bottom: 8px;
}

.crm-kf-val {
  font-size: 24px;
  font-weight: 300;
  color: var(--tx);
  line-height: 1.1;
  margin: 0 0 6px 0;
  font-variant-numeric: tabular-nums;
}

.crm-kf-sub {
  font-size: 12px;
  font-weight: 400;
  color: var(--mu);
  font-variant-numeric: tabular-nums;
}

/* 8. Token Semantic Colors */
.c-green { color: var(--g) !important; }
.c-red, .c-pink { color: var(--r) !important; }
.c-yellow, .c-amber { color: var(--y) !important; }
.c-purple { color: var(--a) !important; }
.c-blue { color: var(--b) !important; }
.c-muted { color: var(--mu) !important; }
.c-normal { color: var(--tx) !important; }

/* Status Words: plain colored words (never boxed pills) */
.crm-status-word {
  font-size: 13px;
  font-weight: 400;
}
.crm-status-word.on-track { color: var(--g); }
.crm-status-word.watch { color: var(--y); }
.crm-status-word.at-risk,
.crm-status-word.overdue { color: var(--r); }
.crm-status-word.booked { color: var(--a); }
.crm-status-word.planned { color: var(--mu); }

/* 9. Tables: 13px, header cells muted regular, 8px vertical padding, 1px bottom border per row, numbers right-aligned */
.crm-table-container {
  width: 100%;
  overflow-x: auto;
  scrollbar-width: thin;
}

.crm-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.crm-table th {
  font-size: 12px;
  font-weight: 400;
  color: var(--mu);
  padding: 8px 8px;
  border-bottom: 1px solid var(--ln);
  white-space: nowrap;
  text-align: left;
}

.crm-table th:first-child,
.crm-table td:first-child {
  padding-left: 0;
}

.crm-table th:last-child,
.crm-table td:last-child {
  padding-right: 0;
}

.crm-table th.num,
.crm-table td.num {
  text-align: right;
}

.crm-table td {
  padding: 8px 8px;
  border-bottom: 1px solid var(--ln);
  color: var(--tx);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.crm-table tr:hover td {
  background: #ffffff08;
}

.crm-table tr.total-row td {
  font-weight: 500;
  color: var(--tx);
}

.crm-footnote {
  font-size: 12px;
  color: var(--mu);
  margin-top: 12px;
}

/* 10. Horizontal Bar Rows (Category Breakdowns) */
/* Label, 6px rounded track in panel-2 with accent fill, value on the right */
.crm-hbar-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.crm-hbar-row {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.crm-hbar-label {
  color: var(--tx);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crm-hbar-track {
  width: 100%;
  height: 6px;
  background: var(--p2);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.crm-hbar-fill {
  height: 100%;
  background: var(--a);
  border-radius: 999px;
  transition: width 150ms ease;
}

.crm-hbar-val {
  color: var(--tx);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
  font-size: 13px;
}

.crm-hbar-val .sub-val {
  color: var(--mu);
  margin-left: 6px;
}

/* 11. Attention List (Needs attention today) */
.crm-attention-list {
  display: flex;
  flex-direction: column;
}

.crm-attention-group {
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--ln);
}

.crm-attention-group:last-child {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: none;
}

.crm-attention-group-title {
  font-size: 13px;
  font-weight: 400;
  color: var(--tx);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}

.crm-attention-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  padding: 3px 0;
  color: var(--mu);
  font-variant-numeric: tabular-nums;
}

.crm-attention-row-divided {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 8px 0;
  border-bottom: 1px solid var(--ln);
  font-variant-numeric: tabular-nums;
}

/* 12. Chart Legend: text with a 10px colour square */
.owner-legend {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  color: var(--mu);
}

.owner-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.owner-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.owner-legend-line {
  width: 14px;
  height: 0;
  border-top: 2px dashed var(--y);
  display: inline-block;
}

/* 13. SVG Charts */
.owner-svg-chart {
  width: 100%;
  height: auto;
  max-height: 200px;
  overflow: visible;
  display: block;
}

.crm-chart-caption {
  font-size: 12px;
  color: var(--mu);
  margin-top: 8px;
}

/* 14. Buttons & Modals (Section 6) */
.owner-btn {
  height: 34px;
  background: var(--p2);
  border: 1px solid var(--ln);
  color: var(--tx);
  padding: 0 14px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease;
}

.owner-btn:hover {
  border-color: var(--a);
}

.owner-btn.btn-primary {
  background: var(--a);
  color: #241d2e;
  font-weight: 500;
  border: none;
}

.owner-btn.btn-primary:hover {
  opacity: 0.92;
}

.owner-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.owner-modal-card {
  background: var(--p);
  border: 1px solid var(--ln);
  border-radius: 14px;
  padding: 20px;
  width: 100%;
  max-width: 480px;
  color: var(--tx);
}

/* 15. 403 Forbidden Screen */
.owner-forbidden-card {
  background: var(--p);
  border: 1px solid var(--ln);
  border-radius: 12px;
  padding: 40px 26px;
  text-align: center;
  max-width: 460px;
  margin: 60px auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* 16. Responsive Breakpoints (Section 5 & 7: 1440, 1100, 900, 390px) */
@media (max-width: 1100px) {
  .crm-key-strip-6 {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 900px) {
  .owner-console {
    padding: 16px 16px 96px;
  }
  .crm-hero-grid,
  .crm-two-col,
  .crm-two-col-equal,
  .crm-three-col {
    grid-template-columns: 1fr;
  }
  .crm-key-strip-6,
  .crm-key-strip-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .owner-console {
    padding: 12px 12px calc(88px + env(safe-area-inset-bottom, 0px));
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  .crm-key-strip-6,
  .crm-key-strip-4 {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .crm-kf-card {
    padding: 14px;
    min-height: auto;
  }

  .crm-kf-val {
    font-size: 20px;
    word-break: break-all;
  }

  .owner-tabs-nav {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    width: 100% !important;
    display: flex !important;
    gap: 16px !important;
    scrollbar-width: none !important;
  }

  .owner-range-segmented {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    display: flex;
    flex-wrap: nowrap;
  }

  .owner-filter-dropdowns {
    width: 100%;
    flex-direction: column;
  }

  .owner-select {
    width: 100%;
    min-height: 44px;
  }

  .crm-table-container {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .owner-svg-chart {
    max-width: 100%;
    overflow: hidden;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
