/* Production Ledger - Material-ish Blue Grey theme */

/* Base palette */
:root {
  --bluegrey-50: #ECEFF1;
  --bluegrey-100: #CFD8DC;
  --bluegrey-200: #B0BEC5;
  --bluegrey-300: #90A4AE;
  --bluegrey-400: #78909C;
  --bluegrey-500: #607D8B;
  --bluegrey-600: #546E7A;
  --bluegrey-700: #455A64;
  --bluegrey-800: #37474F;
  --bluegrey-900: #263238;

  --surface: rgba(38, 50, 56, 0.96);
  --surface-soft: rgba(38, 50, 56, 0.8);
  --border-subtle: #455A64;
  --text-primary: #ECEFF1;
  --text-muted: #B0BEC5;

  /* Will be overridden by theme classes */
  --accent: #607D8B;
}

/* Estimate theme (cyan shift, darker) */
body.theme-estimate {
  --accent: #00838F; /* Cyan 800 */
}

/* Invoice theme (green shift, darker) */
body.theme-invoice {
  --accent: #2E7D32; /* Green 800 */
}

/* Reset / base */

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

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Roboto", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #37474F, #263238);
  color: var(--text-primary);
  min-height: 100vh;
}

/* Typography */

h1, h2, h3, h4 {
  margin: 0 0 0.25rem;
  font-weight: 500;
}

p {
  margin: 0 0 0.5rem;
}

/* Header */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: rgba(18, 24, 28, 0.98);
  border-bottom: 1px solid var(--bluegrey-700);
  backdrop-filter: blur(12px);
}

.app-title-block h1 {
  font-size: 1.1rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.app-title-block p {
  margin: 0;
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--bluegrey-300);
}

.app-header-right {
  display: flex;
  align-items: center;
}

.header-nav {
  display: flex;
  gap: 0.5rem;
}

/* Navigation items */

.header-nav .app-nav-item {
  min-width: 150px;
  padding: 0.4rem 0.9rem;
  border-radius: 4px;
  border: 1px solid var(--bluegrey-500);
  background: transparent;
  color: var(--text-primary);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.header-nav .app-nav-item:hover {
  background: var(--bluegrey-800);
}

.header-nav .app-nav-item.active {
  background: var(--accent);
  border-color: #E0F2F1;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.header-nav .app-nav-item:focus-visible {
  outline: 2px solid var(--bluegrey-50);
  outline-offset: 2px;
}

/* Layout */

.app-main {
  padding: 1.25rem 1.5rem 1.5rem;
}

.app-main-inner {
  max-width: 1280px;
  margin: 0 auto;
}

.app-main-inner.single-column {
  max-width: 720px;
}

.columns {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.column {
  min-width: 0;
}

.column-left {
  flex: 0 0 420px;
}

.column-right {
  flex: 1 1 auto;
}

/* Panels */

.panel {
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  margin-bottom: 0.75rem;
}

.panel-header,
.panel-header-static {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-header {
  background: rgba(96, 125, 139, 0.12);
  border-radius: 8px 8px 0 0;
  cursor: pointer;
}

.panel-header-static {
  background: rgba(96, 125, 139, 0.16);
  border-radius: 8px 8px 0 0;
}

.panel-body {
  padding: 0.75rem 0.8rem 0.9rem;
}

/* Panel toggle indicator */

.panel-toggle-indicator {
  font-size: 0.9rem;
  margin-left: 0.25rem;
  transition: transform 0.15s ease;
}

.panel.collapsed .panel-body {
  display: none;
}

.panel.collapsed .panel-toggle-indicator {
  transform: rotate(180deg);
}

/* Forms */

.field-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.6rem;
}

.field-row.inline {
  flex-direction: row;
  align-items: flex-end;
  gap: 0.75rem;
}

.inline-half {
  flex: 1 1 0;
}

label {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.field-help {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin: 0.25rem 0 0;
}

input,
select,
textarea {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 22, 27, 0.95);
  color: var(--text-primary);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

textarea {
  resize: vertical;
}

/* Buttons */

button {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--bluegrey-50);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}

button.secondary {
  background: transparent;
  color: var(--bluegrey-50);
  border-color: var(--bluegrey-500);
}

button.small {
  font-size: 0.7rem;
  padding: 0.25rem 0.55rem;
}

button:hover {
  background: var(--bluegrey-600);
}

button.secondary:hover {
  background: var(--bluegrey-800);
}

button:active {
  transform: translateY(1px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.35) inset;
}

button:focus-visible {
  outline: 2px solid var(--bluegrey-50);
  outline-offset: 2px;
}

/* Panel actions */

.panel-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  align-items: center;
}

/* Tables */

.table-wrapper {
  max-height: 340px;
  overflow: auto;
}

.items-table-wrapper {
  overflow-x: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

th,
td {
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

th {
  text-align: left;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.65rem;
  cursor: default;
}

th.sortable {
  cursor: pointer;
}

th.sortable::after {
  content: "⇅";
  font-size: 0.6rem;
  margin-left: 0.25rem;
  opacity: 0.5;
}

th.sortable.sorted-asc::after {
  content: "↑";
}

th.sortable.sorted-desc::after {
  content: "↓";
}

td.number,
th.number {
  text-align: right;
}

tbody tr:last-child td {
  border-bottom: none;
}

/* Row hover highlights */

.tracker-table tbody tr:hover,
.client-table tbody tr:hover {
  background: rgba(255,255,255,0.06);
  cursor: pointer;
}

/* Items table column widths */

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

.items-table th:nth-child(1),
.items-table td:nth-child(1) {
  width: 55%;
}

.items-table th:nth-child(2),
.items-table td:nth-child(2) {
  width: 15%;
}

.items-table th:nth-child(3),
.items-table td:nth-child(3) {
  width: 20%;
}

.items-table th:nth-child(4),
.items-table td:nth-child(4) {
  width: 10%;
}

.items-table input[type="text"],
.items-table input[type="number"] {
  width: 100%;
}

.items-table td input[type="number"] {
  text-align: right;
  padding: 0.45rem 0.5rem;
}

/* Remove spinner arrows for number inputs in items table */

.items-table input[type="number"]::-webkit-outer-spin-button,
.items-table input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.items-table input[type="number"] {
  -moz-appearance: textfield;
}

/* Preview */

.preview-panel .panel-body {
  padding: 0.75rem;
}

.preview-body {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  gap: 0.5rem;
}

.preview-actions {
  display: inline-flex;
  gap: 0.4rem;
}

.preview-doc-type-tag {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  padding: 0.18rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--accent);
}

/* Theme-specific tag coloring */
body.theme-estimate .preview-doc-type-tag {
  background: rgba(0, 131, 143, 0.2);
  color: #E0F7FA;
}

body.theme-invoice .preview-doc-type-tag {
  background: rgba(46, 125, 50, 0.2);
  color: #C8E6C9;
}

.preview-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.25rem;
}

.document-preview {
  background: #FAFAFA;
  color: #222;
  padding: 1.1rem 1.2rem;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  min-height: 480px;
  max-width: 850px;
  margin: 0 auto;
}

@media print {
  body {
    background: #ffffff;
  }
  .document-preview {
    box-shadow: none;
    border-radius: 0;
    margin: 0 auto;
  }
}

.document-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.document-total-block {
  min-width: 180px;
}

.document-total-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: #666;
}

.document-total-amount {
  font-size: 1.8rem;
  font-weight: 700;
  margin-top: 0.2rem;
}

.document-company-block h1 {
  font-size: 1.1rem;
  margin-bottom: 0.15rem;
}

.document-logo {
  max-width: 140px;
  max-height: 60px;
  margin-bottom: 0.35rem;
}

.document-section {
  margin-top: 1rem;
}

.document-section h2 {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

/* Acceptance lines */

.acceptance-lines {
  display: flex;
  gap: 1.5rem;
  font-size: 0.7rem;
}

.acceptance-lines span {
  color: var(--text-muted);
}

.document-acceptance-lines {
  display: flex;
  gap: 1.5rem;
  margin-top: 0.5rem;
  font-size: 0.75rem;
}

.document-acceptance-lines .sig-block {
  flex: 1 1 auto;
}

.document-acceptance-lines .sig-block.signature {
  flex: 2 1 auto;
}

.document-acceptance-lines .sig-block.date {
  flex: 0 0 160px;
}

.document-acceptance-lines .sig-line {
  border-bottom: 1px solid #555;
  height: 1.4rem;
  margin-bottom: 0.25rem;
}

.document-acceptance-lines .sig-label {
  color: #777;
}

/* Document meta grid */

.doc-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.4rem 1rem;
  font-size: 0.8rem;
}

.doc-meta-item-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: #777;
}

.doc-meta-item-value {
  font-size: 0.8rem;
}

/* Document tables inside preview */

.document-preview table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.document-preview th,
.document-preview td {
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid #DDD;
}

.document-preview th {
  text-align: left;
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #555;
}

.document-preview td.number,
.document-preview th.number {
  text-align: right;
}

/* Totals row */

.document-totals-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.4rem;
  font-size: 0.8rem;
}

.document-totals-label {
  margin-right: 1rem;
  font-weight: 600;
}

.document-totals-value {
  min-width: 100px;
  text-align: right;
  font-weight: 600;
}

/* Tracker header */

.tracker-header-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.tracker-mode-toggle {
  display: inline-flex;
  gap: 0.25rem;
}

/* Tracker mode buttons - more square, only active highlighted */

.tracker-mode-btn {
  border-radius: 4px;
  background: transparent;
  border-color: var(--bluegrey-500);
  color: var(--bluegrey-50);
}

.tracker-mode-btn.active {
  background: var(--accent);
  border-color: #E0F2F1;
}

/* Tracker */

.tracker-filters {
  margin-bottom: 0.75rem;
}

.tracker-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.tracker-summary-item {
  background: rgba(0,0,0,0.35);
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  min-width: 90px;
}

.tracker-summary-item .label {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.tracker-summary-item .value {
  display: block;
  font-size: 1rem;
  font-weight: 600;
}

/* Period slider */

.period-slider {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.period-slider input[type="range"] {
  width: 100%;
}

.period-slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.6rem;
  color: var(--text-muted);
}

.period-slider-labels span {
  flex: 1 1 0;
  text-align: center;
  opacity: 0.6;
}

.period-slider-labels span.active {
  opacity: 1;
  font-weight: 500;
}

/* Tracker chart */

.tracker-chart {
  background: rgba(0,0,0,0.35);
  border-radius: 4px;
  padding: 0.5rem 0.75rem 0.75rem;
  margin-bottom: 0.75rem;
}

.tracker-chart-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.tracker-chart-bars {
  display: flex;
  align-items: stretch;
  gap: 0.35rem;
  height: 220px;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.tracker-chart-bar {
  flex: 0 0 42px;
  min-width: 42px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  align-items: center;
  gap: 0.15rem;
}

.tracker-chart-bar-track {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
}

.tracker-chart-bar-inner {
  width: 100%;
  max-width: none;
  min-height: 4px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  transition: height 0.15s ease;
}

.tracker-chart-bar-value {
  font-size: 0.6rem;
  margin-bottom: 0;
}

.tracker-chart-bar-label {
  margin-top: 0.25rem;
  font-size: 0.6rem;
  color: var(--text-muted);
}

/* Invoice status tags */

.invoice-status-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-left: 0.25rem;
}

.invoice-status-open {
  background: rgba(96, 125, 139, 0.3);
  color: var(--bluegrey-50);
}

.invoice-status-paid {
  background: rgba(56, 142, 60, 0.3);
  color: #C8E6C9;
}

.invoice-status-overdue {
  background: rgba(211, 47, 47, 0.38);
  color: #FFCDD2;
}

.tracker-table tr.overdue-row td {
  background: rgba(211, 47, 47, 0.12);
}

/* Tracker table tweaks */

.tracker-table select {
  font-size: 0.7rem;
  padding: 0.18rem 0.3rem;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  background: rgba(0,0,0,0.5);
  color: var(--text-primary);
}

/* Tracker row actions */

.tracker-row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.25rem;
  margin-top: 0;
}

.tracker-row-actions .small {
  white-space: nowrap;
}

/* Client overview */

.client-overview {
  display: flex;
  gap: 1rem;
}

.client-overview-item {
  background: rgba(0,0,0,0.35);
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
}

.client-overview-item .label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.client-overview-item .value {
  display: block;
  font-size: 1rem;
  font-weight: 600;
}

/* Logo preview */

.logo-preview-wrapper {
  margin: 0.75rem 0 0;
}

.logo-preview-placeholder {
  border-radius: 4px;
  border: 1px dashed var(--border-subtle);
  padding: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-preview-placeholder img {
  max-height: 60px;
  max-width: 200px;
}

/* Company data actions */

.company-data-actions {
  margin-top: 1rem;
  margin-bottom: 0.5rem;
}

.company-data-buttons {
  margin-top: 0.5rem;
}

.company-data-buttons-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Data import label */

.file-input-label {
  position: relative;
  overflow: hidden;
}

.file-input-label input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* View utility */

.view.view-hidden {
  display: none;
}

/* Responsive */

@media (max-width: 960px) {
  .columns {
    flex-direction: column;
  }

  .column-left {
    flex-basis: auto;
  }

  .header-nav .app-nav-item {
    min-width: auto;
  }

  .document-preview {
    max-width: 100%;
    min-height: auto;
    padding: 1rem;
  }
}

@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .tracker-summary {
    flex-direction: column;
  }

  .preview-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }
}
