* { box-sizing: border-box; }

body {
  font-family: system-ui, sans-serif;
  margin: 0;
  padding: 1rem;
  max-width: 480px;
  margin-inline: auto;
  color: #1a1a1a;
  background: #fafafa;
}

h1 { font-size: 1.25rem; }

.list-heading {
  font-size: 0.9rem;
  color: #444;
  margin: 0 0 0.4rem;
}

.list-heading:not(:first-child) {
  margin-top: 1.25rem;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.user-email {
  font-size: 0.85rem;
  color: #666;
}

#login-view {
  min-height: calc(100vh - 2rem);
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #eff6ff 0%, #fafafa 55%);
  border-radius: 16px;
}

#login-view[hidden] {
  display: none;
}

.login-card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 12px 32px rgba(37, 99, 235, 0.1), 0 2px 6px rgba(0, 0, 0, 0.04);
  text-align: center;
}

.login-card h1 {
  margin: 0 0 1.5rem;
  font-size: 1.3rem;
}

.login-card form {
  text-align: left;
  margin-bottom: 1rem;
}

.login-card .hint {
  margin: 1rem 0 0;
  padding: 0.6rem 0.8rem;
  background: #f8fafc;
  border-radius: 8px;
  line-height: 1.4;
}

/* ID (bukan cuma class) supaya menang lawan aturan grid 2-kolom form lain di layar lebar -
   form login cuma 2 field, tidak butuh grid, dan itu yang bikin ada celah kosong ganjil. */
#login-form {
  display: flex;
  flex-direction: column;
}

#login-form button[type="submit"] {
  width: 100%;
}

.login-card .hint {
  margin: 0;
}

form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

fieldset {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 0.75rem;
  margin: 0;
}

legend {
  padding: 0 0.4rem;
  font-weight: 600;
  font-size: 0.85rem;
  color: #444;
}

label[hidden] {
  display: none;
}

label {
  display: flex;
  flex-direction: column;
  font-size: 0.9rem;
  gap: 0.25rem;
}

input, select, button {
  font-size: 1rem;
  padding: 0.6rem;
  border-radius: 6px;
  border: 1px solid #ccc;
}

button {
  background: #2563eb;
  color: white;
  border: none;
  cursor: pointer;
  padding: 0.7rem;
}

button.tab-btn, button.subtab-btn {
  background: #e5e7eb;
  color: #1a1a1a;
  flex: 1;
}

button.tab-btn.active, button.subtab-btn.active {
  background: #2563eb;
  color: white;
}

/* Kain In (stok masuk, diisi admin gudang), Cutting (proses potong, diisi pemotong),
   Jahit (pengambilan hasil potong, diisi penjahit), dan Barang Jadi (ringkasan, read-only)
   itu 4 konteks berbeda - dibedakan warna aksen: biru, oranye, hijau, ungu. */
.tab-btn[data-tab="cutting"].active {
  background: #ea580c;
}

.tab-btn[data-tab="jahit"].active {
  background: #16a34a;
}

.tab-btn[data-tab="barangjadi"].active {
  background: #7c3aed;
}

#page-title[data-tab="kainin"] { color: #2563eb; }
#page-title[data-tab="cutting"] { color: #ea580c; }
#page-title[data-tab="jahit"] { color: #16a34a; }
#page-title[data-tab="barangjadi"] { color: #7c3aed; }

#tab-cutting legend {
  color: #c2410c;
}

#tab-cutting fieldset {
  border-color: #fdba74;
}

#tab-cutting button[type="submit"] {
  background: #ea580c;
}

#tab-jahit legend {
  color: #15803d;
}

#tab-jahit fieldset {
  border-color: #86efac;
}

#tab-jahit button[type="submit"] {
  background: #16a34a;
}

#tab-kainin .card {
  border-left: 4px solid #2563eb;
}

#tab-cutting .card {
  border-left: 4px solid #ea580c;
}

#tab-jahit .card {
  border-left: 4px solid #16a34a;
}

#tab-barangjadi .card {
  border-left: 4px solid #7c3aed;
}

.table-wrap {
  overflow-x: auto;
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  white-space: nowrap;
}

.table-wrap th, .table-wrap td {
  padding: 0.5rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid #eee;
}

.table-wrap td.wrap-cell {
  white-space: normal;
  min-width: 12rem;
}

.table-wrap th {
  background: #f8f8f8;
  font-size: 0.75rem;
  color: #666;
  text-transform: uppercase;
}

.table-wrap tbody tr:hover {
  background: #fafafa;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.date-nav input[type="date"] {
  flex: 1;
}

.date-nav button {
  width: auto;
  padding: 0.6rem 0.8rem;
}

nav#main-tabs, nav#master-subtabs, nav#admin-subtabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  overflow-x: auto;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.card {
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.6rem;
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  margin-bottom: 0.75rem;
}

.filter-bar label {
  font-size: 0.85rem;
  min-width: 8rem;
  flex: 1;
}

.filter-bar button {
  align-self: flex-end;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.card-date {
  font-weight: 400;
  color: #666;
  font-size: 0.8rem;
}

.card-body {
  color: #444;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.card-stats {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.stat-label {
  display: block;
  font-size: 0.7rem;
  color: #888;
}

.stat-value {
  display: block;
  font-weight: 600;
}

.stat-value.stat-danger { color: #b91c1c; }
.stat-value.stat-success { color: #15803d; }

.card-breakdown {
  margin-top: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px dashed #ddd;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: #333;
}

.breakdown-row span:first-child {
  color: #666;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.list-item-title { font-weight: 600; }
.list-item-sub { font-size: 0.85rem; color: #444; }

.btn-delete {
  background: none;
  color: #b91c1c;
  border: 1px solid #b91c1c;
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  width: auto;
}

.ct-hasil-row {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.ct-hasil-row input {
  flex: 1;
}

.ct-hasil-remove {
  background: none;
  border: 1px solid #b91c1c;
  color: #b91c1c;
  padding: 0.3rem 0.6rem;
  width: auto;
  font-size: 0.8rem;
}

#ct-hasil-add {
  background: none;
  border: 1px dashed #ea580c;
  color: #ea580c;
  width: auto;
  align-self: flex-start;
}

.csv-tools {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dashed #ddd;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.card-note {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: #666;
  font-style: italic;
}

.error {
  color: #b91c1c;
  font-size: 0.85rem;
  min-height: 1.2em;
}

.hint {
  font-size: 0.8rem;
  color: #666;
}

.section-banner {
  padding: 1rem 1.25rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  background: #eef2ff;
}

.section-banner h2 {
  margin: 0 0 0.2rem;
  font-size: 1.1rem;
}

.section-banner p {
  margin: 0;
  font-size: 0.85rem;
  color: #444;
}

#tab-kainin .section-banner {
  background: #dbeafe;
}

#tab-cutting .section-banner {
  background: #ffedd5;
}

#tab-jahit .section-banner {
  background: #dcfce7;
}

#tab-barangjadi .section-banner {
  background: #ede9fe;
}

/* Di layar lebih lebar dari HP (tablet/desktop): pakai ruang yang ada,
   jangan cuma jadi kolom sempit di tengah halaman kosong.
   Ditaruh di akhir file supaya menang lawan aturan dasar di atas (urutan sumber, spesifisitas sama). */
@media (min-width: 700px) {
  body {
    max-width: 900px;
    padding: 2rem;
  }

  form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem 1.5rem;
    align-items: start;
  }

  form button[type="submit"],
  #master-id-preview,
  #ct-hasil-list,
  #ct-hasil-add,
  #jh-info,
  form fieldset {
    grid-column: 1 / -1;
  }

  form fieldset {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem 1.5rem;
    align-items: start;
  }

  /* Kalau Kode disembunyikan (Jenis Kain/Warna), Nama jangan sendirian setengah lebar. */
  #master-id-label[hidden] ~ #master-name-label {
    grid-column: 1 / -1;
  }

  .list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.75rem;
  }
}

/* Owner biasanya buka dari laptop/PC, bukan HP - jadi di layar yang cukup lebar,
   dorong lebih ke tampilan "web dashboard": form ringkas di kiri (nempel saat di-scroll),
   daftar data lebar di kanan. Di bawah 960px tetap seperti breakpoint 700px di atas. */
@media (min-width: 960px) {
  body {
    max-width: 1200px;
  }

  .panel-body {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 2rem;
    align-items: start;
  }

  .panel-form {
    position: sticky;
    top: 1.5rem;
  }

  /* Form di kolom sempit kiri: satu kolom saja, 2 kolom terlalu sempit di 380px. */
  .panel-form form,
  .panel-form form fieldset {
    display: flex;
    flex-direction: column;
  }
}
