/*
 * OPK Doors — Pencil Sketch / Millimeter Paper Theme
 * Enhanced version with visible hand-drawn aesthetic
 */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,400;0,500;0,600;1,400&display=swap');

:root {
  --paper: #f5f3ed;
  --ink: #1a1a1a;
  --ink-light: #666;
  --ink-lighter: #999;
  --border: #c8c2b0;
  --shadow: #c8c2b0;
  --accent: #7a6b52;
  --accent-bg: #ede8df;
  --success: #4a7a4a;
  --warning: #b08a40;
  --danger: #8a4040;
  --grid-light: #e5e0d5;
  --grid-dark: #d5cfc0;
  --card-bg: #faf8f4;
  --topbar-bg: #2c2c2c;
  --topbar-text: #e5e0d5;
  --nav-hover: #c8b280;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 15px; }

body {
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  color: var(--ink);
  line-height: 1.7;
  min-height: 100vh;
  background-color: var(--paper);
  /* Millimeter paper grid */
  background-image:
    linear-gradient(var(--grid-light) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-light) 1px, transparent 1px);
  background-size: 20px 20px;
  background-position: -1px -1px;
}

/* ─── Typography ─── */

h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.5px;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 3px double var(--ink);
  display: inline-block;
}

h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 6px;
  border-bottom: 2px dashed var(--ink-lighter);
}

h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
}

/* ─── Layout ─── */

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px 40px;
}

/* ─── Top Bar ─── */

.top-bar {
  background: #bebab2;
  border-bottom: 3px double var(--ink);
  padding: 14px 28px;
  margin: 0 -20px 30px -20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.top-bar .brand {
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--ink);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.top-bar .brand span {
  font-weight: 400;
  color: var(--ink-light);
}

.top-bar nav a {
  color: var(--ink);
  text-decoration: none;
  margin-left: 24px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 600;
  padding-bottom: 4px;
  border-bottom: 1px solid transparent;
  transition: all 0.2s;
}

.top-bar nav a:hover {
  border-bottom-color: var(--ink);
}

/* ─── Buttons ─── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 22px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: 2px solid var(--ink);
  background: var(--card-bg);
  color: var(--ink);
  transition: all 0.12s;
  box-shadow: 3px 3px 0 var(--shadow);
  letter-spacing: 0.5px;
}

.btn:hover {
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 var(--shadow);
}

.btn:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--shadow);
}

.btn-primary {
  background: #5f5f5f;
  color: var(--paper);
  border-color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
}

.btn-primary:hover {
  background: #333;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.7rem;
  box-shadow: 2px 2px 0 var(--shadow);
}

/* ─── Tables ─── */

.table-wrap {
  background: var(--card-bg);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--shadow);
  margin-bottom: 28px;
  overflow-x: auto;
}

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

thead th {
  background: var(--accent-bg);
  border-bottom: 3px double var(--ink);
  padding: 12px 14px;
  text-align: left;
  font-weight: 700;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--ink);
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px dashed var(--grid-dark);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(0,0,0,0.02); }

/* ─── Status ─── */

.status {
  display: inline-block;
  padding: 3px 10px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: 1.5px solid;
  border-radius: 2px;
}
.status-new { border-color: var(--accent); color: var(--accent); }
.status-imported { border-color: var(--ink-lighter); color: var(--ink-lighter); }
.status-shipped { border-color: var(--success); color: var(--success); }

/* ─── Cards ─── */

.card {
  background: var(--card-bg);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
}

.card-title {
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 2px dashed var(--ink-lighter);
  font-size: 0.9rem;
  letter-spacing: 0.5px;
}

/* ─── Forms ─── */

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 5px;
  color: var(--ink-light);
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85rem;
  border: 2px solid var(--ink);
  background: white;
  border-radius: 0;
  transition: box-shadow 0.2s;
}

.form-control:focus {
  outline: none;
  box-shadow: 3px 3px 0 var(--shadow);
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 4 3-4' fill='none' stroke='%231a1a1a' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

/* ─── Door Type Cards Grid ─── */

.type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}

.type-card {
  background: var(--card-bg);
  border: 2px solid var(--border);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.12s;
  box-shadow: 3px 3px 0 var(--shadow);
}

.type-card:hover {
  border-color: var(--ink);
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 var(--shadow);
}

.type-card.selected {
  border-color: var(--ink);
  background: var(--accent-bg);
  box-shadow: inset 1px 1px 0 rgba(0,0,0,0.1);
}

.type-icon { font-size: 2rem; margin-bottom: 6px; }
.type-code { font-weight: 600; font-size: 1rem; }
.type-desc { font-size: 0.7rem; color: var(--ink-light); margin-top: 4px; }

/* ─── Calculation Result ─── */

.calc-result {
  background: var(--card-bg);
  border: 2px solid var(--ink);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 4px 4px 0 var(--shadow);
}

.calc-result h3 {
  border-bottom: 2px dashed var(--ink-lighter);
  padding-bottom: 10px;
  margin-bottom: 18px;
}

.calc-dimensions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.calc-dim {
  text-align: center;
  padding: 16px;
  border: 2px dashed var(--grid-dark);
  background: rgba(0,0,0,0.01);
}

.calc-dim .dim-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  color: var(--ink-light);
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.calc-dim .dim-value {
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--ink);
}

/* ─── Photo cell with hover zoom ─── */

.photo-cell {
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-thumb {
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--grid-heavy);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-bg);
  overflow: hidden;
  transition: all 0.2s ease;
  cursor: pointer;
  position: relative;
  z-index: 1;
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.photo-thumb svg {
  width: 24px;
  height: 24px;
}

.photo-thumb:hover .hover-enlarge {
  display: block;
}

/* ─── Hover enlarge ─── */
.hover-enlarge {
  display: none;
  position: fixed;
  z-index: 100000;
  width: 360px;
  height: 360px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.3);
  background: var(--card-bg);
  padding: 6px;
  pointer-events: none;
  overflow: hidden;
}
.hover-enlarge img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 4px;
}
/* ─── Category Header ─── */

.cat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 2px dashed var(--ink-lighter);
  gap: 12px;
}

.cat-title {
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  flex-shrink: 0;
}

.cat-actions {
  flex-shrink: 0;
}

@media (max-width: 480px) {
  .cat-header {
    flex-wrap: wrap;
    justify-content: center;
    text-align: center;
  }
  .cat-title {
    width: 100%;
    text-align: center;
    font-size: 0.95rem;
  }
  .cat-actions {
    width: 100%;
    display: flex;
    justify-content: center;
  }
}

/* ─── Responsive Table ─── */

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 600px) {
  .table-responsive table,
  .table-responsive thead,
  .table-responsive tbody,
  .table-responsive tr,
  .table-responsive th,
  .table-responsive td {
    display: block;
  }
  .table-responsive thead {
    display: none; /* hide table headers, use data-label instead */
  }
  .table-responsive tr {
    margin-bottom: 16px;
    border: 2px solid var(--ink);
    box-shadow: 3px 3px 0 var(--shadow);
    padding: 12px;
    background: var(--card-bg);
  }
  .table-responsive td {
    border: none;
    border-bottom: 1px dashed var(--grid-dark);
    padding: 8px 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
  }
  .table-responsive td:last-child {
    border-bottom: none;
  }
  .table-responsive td::before {
    content: attr(data-label);
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--ink-light);
    flex-shrink: 0;
  }
  .table-responsive td.col-actions-cell::before {
    content: '';
    display: none;
  }
  .table-responsive td.col-actions-cell {
    justify-content: center;
    padding-top: 12px;
  }
  .photo-thumb:hover {
    border-color: var(--accent);
  }
  .col-photo { display: none; }
  thead .col-actions { display: none; }
}

/* ─── Component List ─── */

.comp-list { list-style: none; }
.comp-list li {
  padding: 8px 0;
  border-bottom: 1px dashed var(--grid-dark);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
}
.comp-list li:last-child { border-bottom: none; }
.comp-code { font-weight: 600; }
.comp-qty { color: var(--ink-light); }

/* ─── Section dividers with sketch look ─── */

.sketch-divider {
  border: none;
  border-top: 3px double var(--ink);
  margin: 32px 0;
  opacity: 0.3;
}

/* ─── Footer ─── */

.footer {
  text-align: center;
  padding: 32px 0 10px;
  font-size: 0.7rem;
  color: var(--ink-lighter);
  border-top: 2px dashed var(--grid-dark);
  margin-top: 40px;
  letter-spacing: 0.5px;
}

/* ─── Action bar (flex row of buttons/actions) ─── */

.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

/* ─── Responsive ─── */

@media (max-width: 768px) {
  .form-row { grid-template-columns: 1fr; }
  .type-grid { grid-template-columns: repeat(2, 1fr); }
  .top-bar { flex-direction: column; gap: 12px; padding: 12px 16px; }
  .top-bar nav a { margin: 0 10px; }
  .calc-dimensions { grid-template-columns: 1fr 1fr; }
  .action-bar { flex-direction: column; align-items: stretch; }
}

/* ─── Lightbox ─── */

.lightbox {
  display: none;
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.85);
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.lightbox.active {
  display: flex;
}

.lightbox-img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border: 3px solid var(--paper);
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 30px;
  color: var(--paper);
  font-size: 2.5rem;
  font-weight: 300;
  cursor: pointer;
  line-height: 1;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.lightbox-close:hover {
  opacity: 1;
}
