/*
  Own Bygglet theme.
  Layout/type scale originally pulled from the live Bygglet app
  (app.bygglet.com) via DOM inspection on 2026-06-19, so the structure
  matches what the team is already used to. The actual Bygglet logo/wordmark
  is NOT reproduced here (it's their trademark).

  Brand color swapped 2026-06-23 to the company's own color -- same variable
  names everywhere (--navy/--navy-light/--navy-hover/--highlight-bg) so every
  banner, button and active-tab highlight across the whole app picks it up
  automatically. Went red -> toned-down red -> purple over a few rounds of
  feedback that day; also switched the active top-nav tab's label, and the
  default in-text link color used by plain row links in list tables, from the
  brand color to the normal dark body text (--text) for readability, since
  those aren't meant to draw attention the way a banner or button does.
*/

:root {
  --navy: #5b2a6b;
  --navy-light: #7a3d8a;
  --navy-hover: #441f50;
  --bg: #f2f2f2;
  --card-bg: #ffffff;
  --row-alt: #fafafa;
  --highlight-bg: #f1e6f3;
  --border: #e0e0e0;
  --text: #1f2d3d;
  --text-muted: #767676;
  --red: #c0392b;
  --green: #2e7d32;
  --amber: #b9770e;
  --radius: 4px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Roboto", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
}

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

h1, h2, h3 {
  font-weight: 500;
  margin: 0 0 0.6em 0;
}

/* ---------- App shell (horizontal nav, like Bygglet) ---------- */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--navy);
  color: #fff;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.topbar-brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.topbar-brand small {
  font-size: 11px;
  font-weight: 400;
  opacity: 0.65;
  letter-spacing: 0.5px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 18px;
}
.topbar-user {
  text-align: right;
  font-size: 13px;
  line-height: 1.3;
}
.topbar-user .company {
  font-weight: 700;
  display: block;
}
.topbar-user .user {
  opacity: 0.75;
  display: block;
}
.icon-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  opacity: 0.85;
}
.icon-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.12);
  text-decoration: none;
}

.tabbar {
  background: var(--navy);
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}
.tabbar a, .tabbar button {
  display: flex;
  align-items: center;
  padding: 13px 20px;
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.tabbar a:hover, .tabbar button:hover {
  background: var(--navy-light);
  text-decoration: none;
}
.tabbar a.active {
  background: #fff;
  color: var(--text);
}
.tabbar .tabbar-spacer {
  flex: 1;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.content {
  flex: 1;
  padding: 24px 28px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.toolbar .search {
  flex: 1;
  max-width: 360px;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-block;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--navy);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover {
  background: var(--navy-light);
  text-decoration: none;
}
.btn-secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--row-alt);
}
.btn-danger {
  background: var(--red);
}

/* ---------- Cards / lists ---------- */

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

.record-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.record-list li {
  border-bottom: 1px solid var(--border);
}
.record-list li:nth-child(even) {
  background: var(--row-alt);
}
.record-list li:last-child {
  border-bottom: none;
}
.record-list a.record-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  color: var(--text);
  gap: 16px;
}
.record-list a.record-row:hover {
  background: var(--highlight-bg);
  text-decoration: none;
}
.record-row .primary {
  font-weight: 700;
}
.record-row .secondary {
  color: var(--text-muted);
  font-size: 12.5px;
}
.record-row .note {
  color: var(--red);
  font-size: 12.5px;
  text-align: right;
  flex: 1;
}
.record-row .tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--highlight-bg);
  color: var(--navy);
  margin-top: 2px;
}

.empty-state {
  padding: 40px 18px;
  text-align: center;
  color: var(--text-muted);
}

/* ---------- Forms ---------- */

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px 20px;
}
.form-grid .field-full {
  grid-column: 1 / -1;
}
.field label {
  display: block;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.field input[type="text"],
.field input[type="email"],
.field input[type="number"],
.field input[type="url"],
.field input[type="date"],
.field select,
.field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
.field textarea {
  min-height: 70px;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--navy-light);
  box-shadow: 0 0 0 2px var(--highlight-bg);
}
.field .checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.field .checkbox-row input {
  width: auto;
}
.field .errorlist {
  color: var(--red);
  font-size: 12px;
  margin: 4px 0 0;
  list-style: none;
  padding: 0;
}

.form-actions {
  margin-top: 22px;
  display: flex;
  gap: 10px;
}

/* ---------- Detail page ---------- */

.detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
}
.detail-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.detail-section h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.kv-list {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 8px 12px;
  font-size: 14px;
}
.kv-list dt {
  color: var(--text-muted);
}
.kv-list dd {
  margin: 0;
}

.status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 10px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.status-draft { background: #eceff1; color: #455a64; }
.status-sent { background: #fff3cd; color: var(--amber); }
.status-accepted, .status-paid { background: #e2f3e6; color: var(--green); }
.status-declined, .status-overdue { background: #fde2e0; color: var(--red); }

table.simple-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.simple-table th, table.simple-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
table.simple-table th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12.5px;
  text-transform: uppercase;
}
table.simple-table td.num, table.simple-table th.num {
  text-align: right;
}

/* ---------- Sortable table headers (click to sort, like Bygglet) ---------- */

/* Compact, single-line rows with ellipsis truncation, like Bygglet's own
   list views, instead of letting long addresses/notes wrap onto multiple
   lines and blow out the row height. The wrapping div (overflow-x:auto)
   around each table lets you scroll sideways for the rest, same as
   Bygglet does once a list has more columns than fit the viewport. */
table.sortable-table td, table.sortable-table th {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

/* Once a column has been manually resized (table[data-resize-fixed="true"],
   set by sort-table.js when the user drags a handle), the column's width
   comes entirely from its <col> element - drop the 220px cap so columns
   can be dragged wider than that, and so the cap isn't fighting narrower
   drags either. */
table.sortable-table[data-resize-fixed="true"] td,
table.sortable-table[data-resize-fixed="true"] th {
  max-width: none;
}

table.sortable-table th {
  position: relative;
}
table.sortable-table th.sortable {
  cursor: pointer;
  user-select: none;
  padding-right: 20px;
}
table.sortable-table th.sortable:hover {
  color: var(--navy);
}
table.sortable-table th.sortable::after {
  content: "\25B2";
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9px;
  opacity: 0.25;
}
table.sortable-table th.sortable.sort-desc::after {
  content: "\25BC";
}
table.sortable-table th.sortable.sort-asc::after,
table.sortable-table th.sortable.sort-desc::after {
  opacity: 1;
  color: var(--navy-light);
}
table.simple-table tbody tr[onclick]:hover {
  background: var(--highlight-bg);
}

/* ---------- Column resize handles (drag a header edge, like Bygglet) ---------- */

.col-resize-handle {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 2;
}
.col-resize-handle:hover {
  background: var(--navy-light);
  opacity: 0.4;
}
body.col-resizing {
  cursor: col-resize;
  user-select: none;
}

/* ---------- Totals row (Totalt (N st), like Bygglet) ---------- */

table.sortable-table tfoot td {
  font-weight: 700;
  background: var(--row-alt);
  border-top: 2px solid var(--border);
  border-bottom: none;
  white-space: nowrap;
}

.breadcrumb {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.breadcrumb a {
  color: var(--text-muted);
}

.messages {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
}
.messages li {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--highlight-bg);
  color: var(--navy);
  font-size: 13.5px;
}
.messages li.error {
  background: #fde2e0;
  color: var(--red);
}

/* ---------- Project sub-tab strip (Bygglet's project-page tab row) ---------- */

.subtabs {
  display: flex;
  flex-wrap: wrap;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: none;
  margin-top: 4px;
}
.subtabs button {
  background: none;
  border: none;
  border-right: 1px solid var(--border);
  padding: 11px 16px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
}
.subtabs button:hover {
  background: var(--row-alt);
  color: var(--navy);
}
.subtabs button.active {
  color: var(--navy);
  background: var(--highlight-bg);
  box-shadow: inset 0 -2px 0 var(--navy);
}
.subtab-panel {
  display: none;
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--card-bg);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.subtab-panel.active {
  display: block;
}

/* ---------- Summary cards (Tid / Fakturering / Resultat) ---------- */

.summary-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin: 14px 0;
}
.summary-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
}
.summary-card h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  margin: 0 0 8px;
}
.summary-card .figure {
  font-size: 22px;
  font-weight: 700;
  color: var(--navy);
}
.summary-card .sub-figure {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---------- Project page layout: main column + right events panel ---------- */

.project-cols {
  display: flex;
  gap: 18px;
  align-items: flex-start;
}
.project-cols .project-main {
  flex: 1;
  min-width: 0;
}
.project-side {
  width: 300px;
  flex-shrink: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.project-side-tabs {
  display: flex;
  background: var(--navy);
}
.project-side-tabs button {
  flex: 1;
  background: none;
  border: none;
  color: #fff;
  padding: 10px 6px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  cursor: pointer;
  font-family: inherit;
}
.project-side-tabs button.active {
  background: var(--amber);
  color: var(--navy);
}
.project-side-body {
  padding: 14px 16px;
}
.project-side-body select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
}
.project-side-panel {
  display: none;
}
.project-side-panel.active {
  display: block;
}
.project-side-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.project-side-item:last-child {
  border-bottom: none;
}
.project-side-item .primary {
  font-weight: 700;
  display: block;
}
.project-side-item .secondary {
  color: var(--text-muted);
  font-size: 12px;
}

/* ---------- Dropdown menu (Fler funktioner) ---------- */

.dropdown {
  position: relative;
  display: inline-block;
}
.dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(0,0,0,0.12);
  min-width: 220px;
  z-index: 20;
}
.dropdown-menu.open {
  display: block;
}
.dropdown-menu a, .dropdown-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  font-size: 13.5px;
  color: var(--text);
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
}
.dropdown-menu a:hover, .dropdown-menu button:hover {
  background: var(--row-alt);
  text-decoration: none;
}

.inline-table-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin: 12px 0;
  padding: 12px;
  background: var(--row-alt);
  border-radius: var(--radius);
}
.inline-table-form .field {
  margin: 0;
}
.inline-table-form .field label {
  margin-bottom: 2px;
}

/* ---------- Dashboard (Översikt): month switcher, chart, KPI panels ---------- */

.month-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
}
.month-switcher select {
  font-size: 15px;
  font-weight: 700;
  color: var(--navy);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  cursor: pointer;
}
.month-switcher .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--navy);
  text-decoration: none;
  font-weight: 700;
}
.month-switcher .icon-btn:hover {
  background: var(--row-alt);
}

.dashboard-chart-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.dashboard-chart-card h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  color: var(--navy);
  margin: 0 0 14px;
}
.dashboard-chart-card canvas {
  max-height: 320px;
}

.dashboard-panels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 16px;
}
.dashboard-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  background: var(--card-bg);
}
.dashboard-panel.panel-blue {
  background: var(--highlight-bg);
}
.dashboard-panel.panel-green {
  background: #e6f3e8;
}
.dashboard-panel h3 {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--navy);
  margin: 0 0 12px;
}
.dashboard-kv {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  font-size: 13px;
}
.dashboard-kv:last-child {
  border-bottom: none;
}
.dashboard-kv .label {
  color: var(--text-muted);
}
.dashboard-kv .label strong {
  color: var(--text);
  font-weight: 700;
}
.dashboard-kv .value {
  font-weight: 700;
  color: var(--navy);
  white-space: nowrap;
}
@media (max-width: 900px) {
  .dashboard-panels {
    grid-template-columns: 1fr;
  }
}
