:root {
  --brand-navy: #164166;
  --brand-blue: #316892;
  --brand-teal: #169993;
  --brand-teal-dark: #0F726D;
}

* { box-sizing: border-box; }

html, body { overflow-x: hidden; max-width: 100%; }

body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  background: #EDEBE3;
  color: #2B2A26;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--brand-navy);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
}
.brand { padding: 0 8px 22px; border-bottom: 1px solid rgba(255,255,255,0.12); margin-bottom: 18px; }
.brand-logo-wrap { padding: 10px 12px; display: flex; align-items: center; justify-content: center; }
.brand-logo { max-width: 100%; height: auto; display: block; }
.brand-sub { font-size: 11px; color: #A9C2D4; margin-top: 8px; }

.nav-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 8px;
  color: #C9D8E3; font-size: 14px; font-weight: 500;
  text-decoration: none; margin-bottom: 4px;
}
.nav-btn:hover { background: rgba(255,255,255,0.08); }
.nav-btn.active { background: var(--brand-teal); color: #fff; }
.icon { font-style: normal; }
.nav-unread-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: auto;
  background: #E05252; color: #fff; font-size: 10.5px; font-weight: 700;
  border-radius: 10px; line-height: 1;
}

.sidebar-spacer { flex: 1; }

.avatar {
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; color: #fff; font-weight: 700;
  font-family: 'Inter', sans-serif; flex-shrink: 0;
}
.avatar-sm { width: 32px; height: 32px; font-size: 12px; }
.avatar-xs { width: 22px; height: 22px; font-size: 10px; }

.sidebar-user {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 12px; padding: 10px 12px; border-radius: 8px;
  background: rgba(255,255,255,0.07);
}
.sidebar-user-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: #EAF1F6; }
.sidebar-user-role { font-size: 11px; color: #A9C2D4; }
.sidebar-logout { display: inline-flex; align-items: center; justify-content: center; color: #C9D8E3; text-decoration: none; font-size: 16px; padding: 4px 8px; border-radius: 6px; }
.sidebar-logout:hover { background: rgba(255,255,255,0.1); }

/* Content */
.content { flex: 1; min-width: 0; padding: 24px 30px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 8px; padding: 9px 16px;
  font-family: 'Inter', sans-serif; font-weight: 600; font-size: 13.5px;
  cursor: pointer; text-decoration: none; border: none;
}
.btn-primary { background: var(--brand-teal); color: #fff; }
.btn-primary:hover { background: var(--brand-teal-dark); }
.btn-secondary { background: #fff; color: #4A4940; border: 1px solid #DAD7CC; }
.btn-secondary:hover { background: #F5F4F0; }
.btn-block { width: 100%; justify-content: center; }

.link { background: none; border: none; color: #6B6A61; font-size: 12.5px; cursor: pointer; padding: 0; text-decoration: underline; }
.link-danger { background: none; border: none; color: #9C3A3A; font-size: 12.5px; cursor: pointer; padding: 0; text-decoration: underline; }

/* Inputs */
.input {
  width: 100%; padding: 9px 11px; border-radius: 7px;
  border: 1px solid #DAD7CC; font-family: 'Inter', sans-serif; font-size: 13.5px;
  background: #fff; color: #2B2A26; margin-bottom: 14px;
}
.input:focus { outline: none; border-color: var(--brand-teal); box-shadow: 0 0 0 3px rgba(22,153,147,0.18); }
.field-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: #8B8A80; font-weight: 600; margin-bottom: 5px; display: block; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: #2B2A26; margin-bottom: 14px; cursor: pointer; text-transform: none; letter-spacing: normal; font-weight: 500; }
.checkbox-label input { width: auto; margin: 0; }
.crew-checkbox-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.crew-checkbox-group .checkbox-label { margin-bottom: 6px; padding: 4px 6px; border-radius: 6px; }
.crew-checkbox-group .checkbox-label:hover { background: #F5F4F0; }
.searchable-checklist-search + .crew-checkbox-group {
  max-height: 240px; overflow-y: auto; border: 1px solid #E3E1D8; border-radius: 8px; padding: 8px;
}
.company-badge { display: inline-block; font-size: 10.5px; font-weight: 600; color: var(--brand-blue); background: #E7EEF3; padding: 2px 7px; border-radius: 10px; vertical-align: middle; margin-left: 4px; }

.user-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 4px 12px; }
.user-actions form { display: inline-flex; }
.danger-zone { border-color: #F0C9C9; background: #FCF6F6; }

/* Chat */
.chat-card { display: flex; flex-direction: column; height: 65vh; padding: 0; overflow: hidden; }
.chat-window { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 12px; }
.chat-empty { text-align: center; margin: auto; }
.chat-msg { display: flex; align-items: flex-end; gap: 8px; max-width: 75%; }
.chat-msg-me { align-self: flex-end; flex-direction: row-reverse; }
.chat-bubble { background: #F5F4F0; border-radius: 12px; padding: 8px 12px; min-width: 60px; }
.chat-msg-me .chat-bubble { background: var(--brand-teal); color: #fff; }
.chat-msg-author { font-size: 11px; font-weight: 700; color: var(--brand-blue); margin-bottom: 2px; }
.chat-msg-text { font-size: 13.5px; color: #2B2A26; white-space: pre-wrap; word-break: break-word; }
.chat-msg-me .chat-msg-text { color: #fff; }
.chat-msg-time { font-size: 10px; color: #9B998E; margin-top: 3px; text-align: right; }
.chat-msg-me .chat-msg-time { color: rgba(255,255,255,0.75); }
.chat-input-row { display: flex; gap: 10px; padding: 16px 24px; border-top: 1px solid #E3E1D8; background: #FAF9F5; }
.chat-input-row .input { flex: 1; }
.chat-input-wrap { position: relative; flex: 1; }
.chat-input-wrap .input { width: 100%; }

.chat-mention { color: var(--brand-teal); font-weight: 700; text-decoration: underline; }
.chat-msg-me .chat-mention {
  color: #fff; text-decoration: underline; background: rgba(255,255,255,0.22);
  padding: 1px 4px; border-radius: 4px;
}

.mention-dropdown {
  position: absolute; bottom: calc(100% + 6px); left: 0; min-width: 220px; max-width: 320px;
  background: #fff; border: 1px solid #E3E1D8; border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12); overflow: hidden; z-index: 20;
}
.mention-dropdown-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  font-size: 13px; color: #2B2A26; cursor: pointer;
}
.mention-dropdown-item:hover { background: #F5F4F0; }

/* Toolbar */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.search-form { display: flex; gap: 8px; flex: 1 1 240px; min-width: 0; flex-wrap: wrap; }
.search-input { max-width: 280px; margin-bottom: 0; flex: 1 1 160px; min-width: 0; }
.search-form .input { margin-bottom: 0; }
.view-toggle { display: flex; gap: 6px; }
.page-heading { font-family: 'Barlow Condensed', sans-serif; font-weight: 700; font-size: 22px; flex: 1; color: var(--brand-navy); }

/* Flash */
.flash { padding: 10px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 13.5px; font-weight: 500; }
.flash-success { background: #E7F3E9; color: #3E7A4F; }
.flash-error { background: #F7E8E8; color: #9C3A3A; }

/* Cards */
.card { background: #fff; border: 1px solid #E3E1D8; border-radius: 10px; padding: 20px 24px; margin-bottom: 16px; max-width: 100%; overflow-x: auto; }
.card-heading { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: #8B8A80; font-weight: 600; margin-bottom: 12px; }
.form-card { max-width: 480px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.two-col { display: flex; gap: 10px; flex-wrap: wrap; }
.two-col > div, .two-col > input { flex: 1; min-width: 120px; }

.time-picker { display: inline-flex; align-items: center; gap: 4px; }
.time-picker select.input { width: 68px; flex: none; min-width: 0; }
.time-picker-sep { color: #9B998E; font-weight: 600; }

.customer-combobox { position: relative; }
.customer-combobox-list {
  position: absolute; top: calc(100% - 10px); left: 0; right: 0; max-height: 220px; overflow-y: auto;
  background: #fff; border: 1px solid #E3E1D8; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12); z-index: 20;
}
.customer-combobox-item { padding: 8px 12px; font-size: 13.5px; color: #2B2A26; cursor: pointer; }
.customer-combobox-item:hover, .customer-combobox-item.active { background: #F5F4F0; }

/* Collapsible panels */
.collapsible { display: none; }
.collapsible.open { display: block; }
tr.collapsible.open { display: table-row; }
.edit-panel { margin-top: 14px; padding-top: 14px; border-top: 1px dashed #E3E1D8; }

.warehouse-plan-img { display: block; max-width: 100%; height: auto; border: 1px solid #E3E1D8; border-radius: 8px; }

.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(20,19,15,0.55);
  align-items: center; justify-content: center; z-index: 100; padding: 24px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #fff; border-radius: 10px; padding: 20px 24px; max-width: 90vw; max-height: 90vh;
  overflow: auto;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 14px; }
.modal-close {
  background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer;
  color: #6B6A61; padding: 0 4px;
}
.modal-close:hover { color: #2B2A26; }

/* Kanban board */
.board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.board-col { background: #F5F4EF; border-radius: 10px; min-width: 250px; flex: 1; display: flex; flex-direction: column; max-height: calc(100vh - 160px); }
.board-col-header { display: flex; justify-content: space-between; padding: 12px 14px; font-weight: 600; font-size: 13.5px; border-bottom: 1px solid #E3E1D8; }
.board-count { color: #9B998E; font-family: 'JetBrains Mono', monospace; font-size: 12px; }
.board-col-body { padding: 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.board-empty { text-align: center; color: #B0AEA2; font-size: 12.5px; padding: 20px 0; }

/* Ticket cards */
.ticket-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.ticket-card {
  display: block; background: #fff; border: 1px solid #E3E1D8; border-left: 3px dashed #DAD7CC;
  border-radius: 10px; padding: 14px 16px; text-decoration: none; color: inherit;
}
.ticket-card:hover { border-color: var(--brand-teal); }
.ticket-card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.ticket-title { font-weight: 600; font-size: 15px; color: #2B2A26; margin-bottom: 4px; }
.ticket-customer { font-size: 13px; color: #6B6A61; margin-bottom: 10px; }
.ticket-card-bottom { display: flex; justify-content: space-between; align-items: center; font-size: 11.5px; color: #9B998E; }

.customer-card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 4px; }
.customer-card { }

/* Status badges */
.status-badge { display: inline-block; font-weight: 600; font-size: 12px; padding: 3px 10px; border-radius: 20px; transform: rotate(-1.5deg); }
.status-open { background: #E7EEF3; color: var(--brand-blue); }
.status-progress { background: #FBF0DC; color: #B0700F; }
.status-done { background: #E7F3E9; color: #3E7A4F; }
.status-cancelled { background: #F7E8E8; color: #9C3A3A; }

.assignment-row { margin-top: 14px; padding-top: 14px; border-top: 1px dashed #E3E1D8; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.assignment-row .inline-form { margin: 0; }
.assignment-row select { max-width: 220px; margin-bottom: 0; }

.customer-info-panel { margin-top: 14px; padding: 14px 16px; border-top: 1px dashed #E3E1D8; background: #FAF9F5; border-radius: 8px; }
.customer-info-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 24px; font-size: 13.5px; }
.customer-info-grid > div { min-width: 0; }
.customer-info-grid > div > div { overflow-wrap: anywhere; word-break: break-word; }
.customer-info-grid > div > span { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 3px; }

@media (max-width: 480px) {
  .customer-info-grid { grid-template-columns: 1fr; }
}

/* Schedule & timeline */
.schedule-row { margin-bottom: 16px; }
.inline-form { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.inline-form .input { margin-bottom: 0; max-width: 200px; flex: 1 1 140px; min-width: 0; }
.timeline-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding-top: 14px; border-top: 1px dashed #E3E1D8; }
.pdf-report-row { margin-top: 16px; padding-top: 14px; border-top: 1px dashed #E3E1D8; }

.signature-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.signature-block { display: flex; flex-direction: column; }
.signature-canvas {
  width: 100%; max-width: 380px; height: 150px;
  border: 1px dashed #DAD7CC; border-radius: 8px; background: #FAF9F5;
  touch-action: none; cursor: crosshair; margin-top: 6px;
}
.signature-preview {
  width: 100%; max-width: 380px; height: 150px; object-fit: contain;
  border: 1px solid #E3E1D8; border-radius: 8px; background: #fff; margin-top: 6px; margin-bottom: 6px;
}
.signature-actions { display: flex; gap: 8px; margin-top: 8px; }

@media (max-width: 600px) {
  .signature-grid { grid-template-columns: 1fr; }
}
.timeline-value { font-family: 'JetBrains Mono', monospace; font-size: 14px; color: #2B2A26; }
.scheduled-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--brand-blue); background: #E7EEF3; padding: 2px 8px; border-radius: 20px; }

.stats-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card { background: #fff; border: 1px solid #E3E1D8; border-radius: 10px; padding: 14px 16px; }
.stat-value { font-family: 'Barlow Condensed', sans-serif; font-weight: 700; font-size: 26px; color: var(--brand-navy); margin-top: 4px; }

/* Ticket detail */
.ticket-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 10px; }
.ticket-heading { font-family: 'Barlow Condensed', sans-serif; font-weight: 700; font-size: 24px; color: var(--brand-navy); }
.ticket-description { margin-top: 14px; padding-top: 14px; border-top: 1px dashed #E3E1D8; font-size: 14px; line-height: 1.5; }

/* Materials */
.simple-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.simple-table td, .simple-table th { padding: 10px 4px; border-bottom: 1px solid #F0EFE8; text-align: left; }
.simple-table.wide th { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em; color: #6B6A61; background: #FAF9F5; padding: 10px 14px; }
.simple-table.wide td { padding: 10px 14px; }
.align-right { text-align: right; }
.low-stock { color: #9C3A3A; font-weight: 600; }
.low-stock-tag { margin-left: 8px; font-size: 11px; color: #9C3A3A; }

.material-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-top: 8px; }
.material-form-field { flex: 1; min-width: 180px; }
.material-form-qty { width: 110px; }
.material-form .input { margin-bottom: 0; }

.serial-chip {
  font-family: 'JetBrains Mono', monospace; font-size: 11.5px;
  background: #E7EEF3; color: var(--brand-blue); border: none;
  padding: 4px 9px; border-radius: 14px; cursor: pointer;
}
.serial-chip:hover { background: #F7E8E8; color: #9C3A3A; }
.serial-chip-used { background: #F0EFE8; color: #8B8A80; cursor: default; }
.serial-chip-used:hover { background: #F0EFE8; color: #8B8A80; }
.serial-check-label {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: 'JetBrains Mono', monospace; font-size: 12px;
  background: #F5F4F0; border: 1px solid #DAD7CC; border-radius: 8px;
  padding: 5px 10px; cursor: pointer;
}
.serial-check-label input { width: auto; margin: 0; }

.mono { font-family: 'JetBrains Mono', monospace; }
.muted { color: #9B998E; }
.small { font-size: 11.5px; }
.empty-state { text-align: center; padding: 60px 0; color: #9B998E; }

@media (max-width: 780px) {
  .app-shell { flex-direction: column; }

  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 10px 14px;
    gap: 8px 12px;
  }
  .brand { border: none; padding: 0; margin: 0; flex: 0 0 auto; }
  .brand-logo-wrap { padding: 6px 8px; }
  .brand-logo { max-height: 26px; width: auto; }
  .brand-sub { display: none; }

  .sidebar-spacer { display: none; }

  nav {
    display: flex;
    gap: 4px;
    order: 3;
    flex: 1 1 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-top: 8px;
    margin-top: 4px;
    border-top: 1px solid rgba(255,255,255,0.1);
  }
  .nav-btn { white-space: nowrap; padding: 8px 12px; font-size: 13px; margin-bottom: 0; }

  .btn-block { width: auto; order: 2; padding: 8px 14px; font-size: 12.5px; }

  .sidebar-user {
    order: 1; margin: 0 0 0 auto; margin-left: auto;
    background: none; padding: 0; gap: 8px;
  }
  .sidebar-user-name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar-user-role { display: none; }

  .content { padding: 16px; max-width: 100%; }

  .toolbar { gap: 8px; }
  .search-form { flex: 1 1 100%; }
  .view-toggle { flex: 1 1 auto; }
  .view-toggle .btn, .toolbar > .btn { flex: 1; justify-content: center; }
  .page-heading { flex: 1 1 100%; }

  .ticket-grid { grid-template-columns: 1fr; }
  .stats-summary { grid-template-columns: 1fr 1fr; }

  .board { margin: 0 -16px; padding: 0 16px 8px; }
  .board-col { min-width: 220px; }

  .ticket-header { flex-direction: column; align-items: stretch; }
  .ticket-header select { width: 100%; }

  .timeline-grid { grid-template-columns: 1fr; gap: 12px; }

  .material-form, .schedule-row .inline-form, .assignment-row { flex-direction: column; align-items: stretch; }
  .material-form-qty, .assignment-row select, .inline-form .input { max-width: none; width: 100%; }
  .material-form .btn, .assignment-row form { width: 100%; }

  .two-col { flex-direction: column; }

  .simple-table.wide { display: block; }
  .simple-table.wide thead { display: none; }
  .simple-table.wide tbody, .simple-table.wide tr, .simple-table.wide td { display: block; width: 100%; }
  .simple-table.wide tr { border-bottom: 1px solid #E3E1D8; padding: 10px 0; }
  .simple-table.wide td { padding: 3px 0; border: none; }
  .simple-table.wide td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.03em;
    color: #9B998E; font-weight: 600; margin-bottom: 2px;
  }
  .simple-table.wide td.align-right { text-align: left; margin-top: 4px; }
  .user-actions { justify-content: flex-start; }
}

@media (max-width: 420px) {
  .stats-summary { grid-template-columns: 1fr; }
  .ticket-heading { font-size: 20px; }
  .card { padding: 16px; }
}
