:root {
  --bg: #f3f5fb;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --blue: #2563eb;
  --red: #dc2626;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
}

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

.sidebar {
  background: #0f172a;
  color: #fff;
  padding: 18px 16px;
  border-right: 1px solid #1e293b;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}

.sidebar h1 {
  margin: 0;
  font-size: 18px;
  white-space: nowrap;
}

.sidebar-brand-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.sidebar-brand-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex: 0 0 28px;
}

.sidebar-brand-title {
  font-size: 16px;
  font-weight: 700;
}

.sidebar p {
  margin: 6px 0 16px;
  font-size: 12px;
  color: #cbd5e1;
}

.nav-auth {
  display: grid;
  gap: 8px;
  margin: 0 0 12px;
}

.menu {
  display: grid;
  gap: 6px;
}

.menu-link {
  color: #cbd5e1;
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.menu-icon {
  width: 20px;
  text-align: center;
  flex: 0 0 20px;
}

.menu-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-link.active,
.menu-link:hover {
  background: #1e293b;
  border-color: #334155;
  color: #fff;
}

.menu-separator {
  margin: 8px 8px 4px;
  padding-top: 8px;
  border-top: 1px solid #334155;
  color: #94a3b8;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar-actions {
  margin-top: 16px;
  display: grid;
  gap: 8px;
}

.content {
  padding: 18px;
  display: grid;
  gap: 14px;
  min-width: 0;
  overflow-x: hidden;
  align-content: start;
}

.page-header h2 {
  margin: 0;
  font-size: 22px;
}

.page-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.page-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.yd-mode-btn {
  min-width: 150px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  min-width: 0;
}

.panel h3 {
  margin: 0 0 10px;
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
}

.btn:hover {
  filter: brightness(0.98);
}

.btn.small {
  padding: 6px 10px;
  font-size: 12px;
}

.btn.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.btn.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.btn.danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.btn.ghost {
  background: transparent;
  color: #e2e8f0;
  border-color: #475569;
}

.full-width {
  width: 100%;
}

.kpi-grid,
.summary-grid,
.card-list,
.scope-boards {
  display: grid;
  gap: 10px;
}

.kpi-grid {
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
}

.summary-grid {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.kpi-card,
.summary-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.kpi-card {
  min-height: 92px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  box-shadow: 0 2px 8px rgba(30, 64, 175, 0.06);
}

.summary-card {
  background: #ffffff;
}

.kpi-title,
.summary-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.kpi-value,
.summary-card strong {
  margin: 8px 0 0;
  display: block;
  font-size: 21px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  text-align: right;
}

.insight-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.insight-card {
  border: 1px solid #dbe7ff;
  border-radius: 12px;
  padding: 12px;
  background: linear-gradient(135deg, #f8fbff 0%, #eef4ff 100%);
}

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

.insight-title {
  margin: 2px 0 10px;
  font-size: 14px;
}

.table-wrap.compact .data-table th,
.table-wrap.compact .data-table td {
  padding: 8px 10px;
  font-size: 13px;
}

.customer-card,
.scope-board {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.customer-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

.customer-head h4 {
  margin: 0;
}

.customer-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.profile-launch {
  margin-left: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid #334155;
  background: #1e293b;
  color: #e2e8f0;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}

.profile-launch:hover {
  background: #334155;
  color: #fff;
}

.badge {
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 12px;
  padding: 5px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

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

.mini-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.mini-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.mini-grid strong {
  font-size: 16px;
}

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

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

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

input[type="checkbox"],
input[type="radio"] {
  width: 16px;
  min-width: 16px;
  max-width: 16px;
  height: 16px;
  padding: 0;
  margin: 0;
  border-radius: 4px;
  flex: 0 0 16px;
}

select[multiple] {
  min-height: 110px;
}

.combo-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  width: 100%;
  min-width: 0;
  position: relative;
}

.combo-box > summary {
  list-style: none;
  cursor: pointer;
  display: block;
  padding: 8px 10px;
  padding-right: 28px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  min-width: 0;
}

.combo-box > summary::-webkit-details-marker {
  display: none;
}

.combo-box > summary::after {
  content: "▾";
  float: right;
  color: var(--muted);
}

.combo-box[open] > summary::after {
  content: "▴";
}

.combo-box[open] {
  z-index: 30;
}

.combo-box-menu {
  border-top: 1px solid var(--line);
  max-height: 180px;
  overflow-y: auto;
  padding: 6px 8px;
  display: grid;
  gap: 6px;
  position: relative;
  z-index: 31;
}

.combo-box-menu label {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 13px;
}

.combo-box-menu label span {
  min-width: 0;
}

.full-width {
  grid-column: 1 / -1;
}

.milestone-row {
  margin: 10px 0;
  display: flex;
  gap: 14px;
}

.milestone-row label {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.product-table-wrap {
  overflow-x: auto;
}

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

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

.scope-list,
.request-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

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

.filter-grid label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  min-width: 0;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

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

.data-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
}

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

.data-table th {
  color: var(--muted);
  font-weight: 600;
}

.data-table th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 22px;
}

.data-table th.sortable::after {
  content: "↕";
  position: absolute;
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: #94a3b8;
}

.data-table th.sortable[data-sort-dir="asc"]::after {
  content: "↑";
  color: #1d4ed8;
}

.data-table th.sortable[data-sort-dir="desc"]::after {
  content: "↓";
  color: #1d4ed8;
}

.data-table th.sorted-active {
  background: #eef2ff;
  color: #1e3a8a;
}

.data-table td.sorted-col {
  background: #f8fbff;
}

.deal-products-cell {
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
  word-break: break-word;
  min-height: 2.7em;
}

.deals-table {
  table-layout: fixed;
}

.deals-table th:nth-child(1),
.deals-table td:nth-child(1) {
  width: 110px;
}

.deals-table th:nth-child(2),
.deals-table td:nth-child(2) {
  width: 180px;
}

.deals-table th:nth-child(3),
.deals-table td:nth-child(3) {
  width: 120px;
}

.deals-table th:nth-child(4),
.deals-table td:nth-child(4),
.deals-table th:nth-child(5),
.deals-table td:nth-child(5) {
  width: 120px;
}

.deals-table th:nth-child(6),
.deals-table td:nth-child(6) {
  width: 220px;
}

.deals-table th:nth-child(7),
.deals-table td:nth-child(7) {
  width: 140px;
}

.deals-table td {
  white-space: normal;
}

.app-message-container {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 2600;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

.app-message-container.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.app-message {
  max-width: 420px;
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.14);
  font-size: 13px;
}

.app-message.error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}

.app-message.success {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #166534;
}

.scope-item,
.request-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font-size: 13px;
}

.scope-item.done {
  background: #ecfdf5;
  border-color: #86efac;
}

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

.yd-widget .preset-row {
  margin-bottom: 0;
}

.yd-widget-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: 24px;
  height: 24px;
  min-width: 24px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-size: 12px;
  border-radius: 6px;
}

.icon-btn.danger {
  font-weight: 700;
  font-size: 13px;
}

.yd-widget-kpi {
  min-height: 132px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  box-shadow: 0 2px 8px rgba(30, 64, 175, 0.06);
}

.yd-widget-kpi .customer-head {
  margin-bottom: 6px;
}

.yd-widget .customer-head h4 {
  margin: 0;
  font-size: 12px;
  line-height: 1.25;
}

.yd-widget-result {
  width: 100%;
}

.yd-widget-kpi .yd-widget-result {
  margin-top: auto;
}

.yd-widget-table {
  margin-bottom: 10px;
}

.yd-kpi-value {
  margin-top: 8px;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.yd-kpi-value-text {
  font-size: 17px;
  line-height: 1.25;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  white-space: normal;
  word-break: break-word;
}

.yd-kpi-text-main {
  font-weight: 700;
}

.yd-kpi-text-sub {
  font-size: 24px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.yd-inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
}

.yd-inline-check input[type="checkbox"] {
  width: auto;
}

.yd-sql-textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 13px;
}

.note-textarea {
  width: 100%;
  min-height: 96px;
  resize: vertical;
  font: inherit;
}

.tag {
  display: inline-block;
  border-radius: 999px;
  font-size: 11px;
  padding: 2px 8px;
}

.tag.out {
  background: #ffedd5;
  color: #9a3412;
}

.tag.bill {
  background: #fef3c7;
  color: #92400e;
}

.workflow-grid {
  display: block;
}

.workflow-timeline,
.workflow-inline {
  display: grid;
  gap: 8px;
}

.workflow-timeline {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.workflow-inline {
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
}

.wf-step {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  min-width: 0;
}

.wf-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.wf-owner {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 600;
}

.wf-step.done {
  border-color: #86efac;
  background: #f0fdf4;
}

.wf-step.current {
  border-color: var(--blue);
  background: #eff6ff;
}

.wf-step.pending {
  opacity: 0.8;
}

.progress-wrap {
  min-width: 110px;
}

.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--blue);
}

.dates-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.dates-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  min-width: 0;
}

.dates-grid > *,
.filter-grid > * {
  min-width: 0;
}

.sidebar-toggle {
  border: 1px solid #334155;
  background: transparent;
  color: #e2e8f0;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  margin-bottom: 10px;
}

body.sidebar-collapsed .app-shell {
  grid-template-columns: 72px 1fr;
}

body.sidebar-collapsed .sidebar h1,
body.sidebar-collapsed .sidebar p,
body.sidebar-collapsed .menu-text,
body.sidebar-collapsed .sidebar-actions,
body.sidebar-collapsed .nav-auth {
  display: none;
}

body.sidebar-collapsed .menu-link {
  justify-content: center;
  padding: 10px 8px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #f3f6fb;
}

.login-card {
  width: min(420px, 92vw);
  background: #fff;
  border: 1px solid #d8e0f0;
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(19, 39, 68, 0.12);
}

.login-logo {
  width: 132px;
  height: 132px;
  margin: 0 auto 12px;
  display: flex;
  justify-content: center;
}

.login-logo img {
  width: 132px;
  height: 132px;
  object-fit: contain;
  display: block;
}

.profile-panel {
  max-width: 560px;
}

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

.login-card h1 {
  text-align: center;
  margin-top: 0;
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form label {
  display: grid;
  gap: 4px;
}

.login-error {
  color: #c62828;
  min-height: 20px;
  margin: 8px 0 0;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

.modal-backdrop.is-hidden {
  display: none;
}

.modal-card {
  width: min(960px, 96vw);
  max-height: 85vh;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.modal-header h3 {
  margin: 0;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    top: auto;
    height: auto;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid #1e293b;
  }

  .content {
    padding: 14px;
  }

  .page-header h2 {
    font-size: 20px;
  }

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

  .menu-link {
    min-height: 40px;
  }

  body.sidebar-collapsed .app-shell {
    grid-template-columns: 1fr;
  }

  body.sidebar-collapsed .sidebar h1,
  body.sidebar-collapsed .sidebar p {
    display: block;
  }

  body.sidebar-collapsed .menu-text {
    display: inline;
  }

  body.sidebar-collapsed .sidebar-actions,
  body.sidebar-collapsed .nav-auth {
    display: grid;
  }

  body.sidebar-collapsed .menu-link {
    justify-content: flex-start;
    padding: 8px 10px;
  }

  .preset-row > * {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
  }

  .preset-row .btn {
    min-height: 38px;
  }

  .mini-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

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

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

  .workflow-timeline,
  .workflow-inline {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 640px) {
  .content {
    padding: 10px;
    gap: 10px;
  }

  .panel {
    padding: 10px;
    border-radius: 10px;
  }

  .page-header h2 {
    font-size: 18px;
  }

  .page-header p {
    font-size: 12px;
  }

  .sidebar {
    padding: 12px 10px;
  }

  .sidebar .menu {
    grid-template-columns: 1fr;
  }

  .preset-row > * {
    flex: 1 1 100%;
  }

  .btn {
    min-height: 38px;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  .kpi-value,
  .summary-card strong {
    font-size: 18px;
  }

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

  .login-shell {
    padding: 12px;
    place-items: start center;
  }

  .login-card {
    width: 100%;
    max-width: 100%;
    margin-top: 16px;
    padding: 16px;
    border-radius: 12px;
  }

  .login-logo,
  .login-logo img {
    width: 96px;
    height: 96px;
  }

  .app-message-container {
    left: 10px;
    right: 10px;
    top: 10px;
  }

  .app-message {
    max-width: none;
  }

  .combo-box-menu {
    max-height: 40vh;
  }

  .yd-kpi-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1440px) {
  .dates-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1600px) {
  .yd-kpi-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}
