/* ==========================================================================
   LONVY Auftragsplattform — Design System
   Cremeweiss, champagner-/salbeigruene Metallic-Akzente (Kap. 9)
   ========================================================================== */
:root {
  --cream:      #F6F2E9;
  --cream-2:    #FBF9F2;
  --card:       #FFFFFF;
  --ink:        #3B3A33;
  --ink-soft:   #6F6B5F;
  --ink-faint:  #9A9585;
  --sage:       #8B9178;
  --sage-dark:  #656B52;
  --sage-soft:  #EDEFE6;
  --champagne:  #B9AE92;
  --champagne-soft: #F2ECDD;
  --line:       #E7E0D1;
  --line-soft:  #F0EADD;
  --gruen:      #7C9070;
  --gelb:       #C6A02C;
  --rot:        #BB5A44;
  --shadow:     0 1px 2px rgba(70,64,45,.05), 0 6px 20px rgba(70,64,45,.06);
  --shadow-sm:  0 1px 2px rgba(70,64,45,.07);
  --radius:     14px;
  --radius-sm:  9px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--cream);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--sage-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-weight: 600; letter-spacing: -0.01em; color: var(--ink); margin: 0 0 .4em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
small { color: var(--ink-soft); }
hr { border: none; border-top: 1px solid var(--line); margin: 1.2rem 0; }

/* ---- Layout -------------------------------------------------------------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--cream-2);
  border-right: 1px solid var(--line); padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.sidebar .brand img { width: 40px; height: 40px; object-fit: contain; border-radius: 8px; }
.sidebar .brand .name { font-weight: 700; letter-spacing: .14em; font-size: .95rem; color: var(--sage-dark); }
.sidebar .brand .sub { font-size: .62rem; color: var(--ink-faint); letter-spacing: .08em; text-transform: uppercase; }
.nav-link {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px;
  border-radius: var(--radius-sm); color: var(--ink-soft); font-weight: 500;
  font-size: .92rem;
}
.nav-link:hover { background: var(--sage-soft); text-decoration: none; color: var(--ink); }
.nav-link.active { background: var(--sage); color: #fff; }
.nav-link .ic { width: 18px; text-align: center; opacity: .9; }
.nav-sep { border-top: 1px solid var(--line); margin: 10px 6px; }
.sidebar .spacer { flex: 1; }
.nav-foot { font-size: .74rem; color: var(--ink-faint); padding: 6px 12px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 12px 26px;
  border-bottom: 1px solid var(--line); background: rgba(251,249,242,.85);
  backdrop-filter: saturate(1.2) blur(6px); position: sticky; top: 0; z-index: 20;
}
.topbar .page-title { font-weight: 600; font-size: 1.05rem; }
.topbar .grow { flex: 1; }
.content { padding: 24px 26px 60px; max-width: 1280px; width: 100%; }

/* ---- Buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  padding: 8px 15px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-weight: 550; font-size: .9rem;
  cursor: pointer; transition: .12s; font-family: inherit; text-decoration: none;
}
.btn:hover { border-color: var(--champagne); background: var(--cream-2); text-decoration: none; }
.btn-primary { background: var(--sage); border-color: var(--sage); color: #fff; }
.btn-primary:hover { background: var(--sage-dark); border-color: var(--sage-dark); }
.btn-danger { color: var(--rot); border-color: #E7C9C1; }
.btn-danger:hover { background: #FBEFEC; border-color: var(--rot); }
.btn-sm { padding: 5px 10px; font-size: .82rem; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--sage-soft); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-block { width: 100%; }

/* ---- Cards & tables ------------------------------------------------------ */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 18px 20px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 12px; align-items: center; }
.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }

table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.tbl th { text-align: left; font-weight: 600; color: var(--ink-soft); padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
table.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.tbl tr:hover td { background: var(--cream-2); }
table.tbl tr:last-child td { border-bottom: none; }

/* ---- Forms --------------------------------------------------------------- */
label.field { display: block; margin-bottom: 14px; }
label.field > .lbl, .lbl { display: block; font-weight: 600; font-size: .82rem; margin-bottom: 5px; color: var(--ink); }
.req { color: var(--rot); }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-family: inherit; font-size: .92rem; background: var(--card); color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--sage); box-shadow: 0 0 0 3px var(--sage-soft); }
textarea { resize: vertical; min-height: 72px; }
.hint { font-size: .78rem; color: var(--ink-faint); margin-top: 4px; }
.inline-radios { display: flex; flex-direction: column; gap: 7px; }
.inline-radios.horiz { flex-direction: row; flex-wrap: wrap; gap: 14px; }
.radio-line, .check-line { display: flex; align-items: flex-start; gap: 8px; font-weight: 450; cursor: pointer; }
.radio-line input, .check-line input { margin-top: 3px; width: auto; }
fieldset.section { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin: 0 0 18px; background: var(--card); }
fieldset.section > legend { font-weight: 600; padding: 0 8px; color: var(--sage-dark); font-size: .95rem; }

/* ---- Badges & pills ------------------------------------------------------ */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 600; background: var(--sage-soft); color: var(--sage-dark); }
.badge.kat { background: var(--champagne-soft); color: #8a7a51; }
.badge.gray { background: #EEEAE0; color: var(--ink-soft); }
.badge.hold { background: #FBF1D8; color: #9a7a1e; }
.badge.lost { background: #F8E4DE; color: var(--rot); }
.badge.archived { background: #E9E6DD; color: var(--ink-faint); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.gruen { background: var(--gruen); } .dot.gelb { background: var(--gelb); } .dot.rot { background: var(--rot); }
.ampel { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; }
.ampel.gruen { color: var(--gruen); } .ampel.gelb { color: #9a7a1e; } .ampel.rot { color: var(--rot); }

.avatar { width: 28px; height: 28px; border-radius: 50%; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: .72rem; font-weight: 700; flex-shrink: 0; }
.avatar.sm { width: 22px; height: 22px; font-size: .62rem; }
.avatar-stack { display: flex; }
.avatar-stack .avatar { margin-left: -6px; border: 2px solid var(--card); }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* ---- Flash --------------------------------------------------------------- */
.flash { padding: 11px 16px; border-radius: var(--radius-sm); margin-bottom: 18px; font-weight: 500; font-size: .9rem; border: 1px solid; }
.flash.success { background: #EFF3E9; border-color: #CFDCC0; color: var(--sage-dark); }
.flash.error { background: #FBEEEA; border-color: #EDCFC6; color: var(--rot); }

/* ---- Kanban -------------------------------------------------------------- */
.board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.col { flex: 0 0 268px; background: var(--cream-2); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 190px); }
.col-head { padding: 11px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--cream-2); border-radius: var(--radius) var(--radius) 0 0; }
.col-head .ph-nr { width: 22px; height: 22px; border-radius: 6px; background: var(--sage); color: #fff; font-size: .72rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; margin-right: 8px; }
.col-head .ph-name { font-weight: 600; font-size: .85rem; }
.col-head .cnt { font-size: .74rem; color: var(--ink-faint); font-weight: 600; }
.col-body { padding: 10px; display: flex; flex-direction: column; gap: 9px; overflow-y: auto; }
.kcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 12px; box-shadow: var(--shadow-sm); display: block; color: inherit; }
.kcard:hover { border-color: var(--champagne); text-decoration: none; transform: translateY(-1px); transition: .12s; }
.kcard .nr { font-size: .72rem; color: var(--ink-faint); font-weight: 600; letter-spacing: .02em; }
.kcard .ttl { font-weight: 600; margin: 2px 0 4px; font-size: .9rem; line-height: 1.3; }
.kcard .doc { font-size: .8rem; color: var(--ink-soft); }
.kcard .meta { display: flex; align-items: center; justify-content: space-between; margin-top: 9px; }
.kcard .days { font-size: .72rem; color: var(--ink-faint); }
.col-empty { color: var(--ink-faint); font-size: .8rem; text-align: center; padding: 16px 6px; }

/* ---- Stat tiles ---------------------------------------------------------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 17px; }
.tile .num { font-size: 1.7rem; font-weight: 700; color: var(--ink); letter-spacing: -.02em; }
.tile .lab { font-size: .8rem; color: var(--ink-soft); margin-top: 2px; }
.tile.warn .num { color: var(--rot); }

/* ---- Order header & tabs ------------------------------------------------- */
.order-head { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 18px; }
.phasebar { display: flex; gap: 4px; margin: 16px 0 6px; }
.phasebar .seg { flex: 1; height: 7px; border-radius: 4px; background: var(--line); position: relative; }
.phasebar .seg.done { background: var(--sage); }
.phasebar .seg.current { background: var(--champagne); }
.phase-labels { display: flex; gap: 4px; font-size: .64rem; color: var(--ink-faint); }
.phase-labels span { flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phase-labels span.current { color: var(--sage-dark); font-weight: 700; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tab { padding: 10px 15px; font-weight: 550; color: var(--ink-soft); border-bottom: 2px solid transparent; white-space: nowrap; font-size: .92rem; }
.tab:hover { color: var(--ink); text-decoration: none; }
.tab.active { color: var(--sage-dark); border-bottom-color: var(--sage); }
.tab .badge { margin-left: 5px; }

/* ---- Activity stream ----------------------------------------------------- */
.stream { display: flex; flex-direction: column; gap: 2px; }
.act { display: flex; gap: 11px; padding: 10px 2px; border-bottom: 1px solid var(--line-soft); }
.act .body { flex: 1; }
.act .who { font-weight: 600; font-size: .88rem; }
.act .when { font-size: .74rem; color: var(--ink-faint); }
.act.system { color: var(--ink-soft); font-size: .86rem; }
.act.system .ic { color: var(--champagne); }
.act .txt { margin-top: 2px; white-space: pre-wrap; }
.mention { color: var(--sage-dark); font-weight: 600; background: var(--sage-soft); padding: 0 4px; border-radius: 4px; }

/* ---- Misc ---------------------------------------------------------------- */
.def-list { display: grid; grid-template-columns: 165px 1fr; gap: 8px 14px; font-size: .9rem; }
.def-list dt { color: var(--ink-soft); font-weight: 500; }
.def-list dd { margin: 0; }
.muted { color: var(--ink-faint); }
.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.empty { text-align: center; color: var(--ink-faint); padding: 40px 20px; }
.empty .ic { font-size: 2rem; opacity: .5; display: block; margin-bottom: 8px; }
.ing-row { display: grid; grid-template-columns: 2fr 1fr .8fr .8fr 2fr auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.ing-row input { padding: 7px 9px; }
details.rezeptur { border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 12px; background: var(--card); }
details.rezeptur > summary { padding: 12px 15px; cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 10px; }
details.rezeptur > summary::-webkit-details-marker { display: none; }
details.rezeptur[open] > summary { border-bottom: 1px solid var(--line); }
.mono { font-variant-numeric: tabular-nums; }

/* Dropdown */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow); min-width: 220px; z-index: 40; padding: 6px; display: none; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu button, .dropdown-menu a { display: block; width: 100%; text-align: left; padding: 8px 11px; border: none; background: none; border-radius: 7px; cursor: pointer; font-size: .88rem; color: var(--ink); font-family: inherit; }
.dropdown-menu button:hover, .dropdown-menu a:hover { background: var(--sage-soft); text-decoration: none; }
.dropdown-menu button:disabled { color: var(--ink-faint); cursor: not-allowed; }
.dropdown-menu .dd-sep { border-top: 1px solid var(--line-soft); margin: 5px 0; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(59,58,51,.42); z-index: 100; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-bg.open { display: flex; }
.modal { background: var(--card); border-radius: var(--radius); max-width: 560px; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

/* Login */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(160deg, var(--cream) 0%, var(--champagne-soft) 100%); }
.auth-card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 34px 32px; width: 100%; max-width: 400px; }
.auth-card .logo { text-align: center; margin-bottom: 20px; }
.auth-card .logo img { width: 76px; height: 76px; object-fit: contain; }
.auth-card h1 { text-align: center; font-size: 1.2rem; }
.auth-card .sub { text-align: center; color: var(--ink-faint); font-size: .85rem; margin-bottom: 22px; }

/* Breite Tabellen scrollen horizontal innerhalb ihrer Karte statt die Seite zu sprengen */
.tscroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Mobile */
.menu-btn { display: none; }
@media (max-width: 880px) {
  .app { flex-direction: column; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 60; width: 250px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px 14px 60px; }
  .topbar { padding: 10px 14px; position: sticky; }
  .topbar .page-title { font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .def-list { grid-template-columns: 1fr; gap: 2px 0; }
  .def-list dt { margin-top: 8px; }
  .ing-row { grid-template-columns: 1fr 1fr; gap: 6px; }
  .scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; }
  .scrim.open { display: block; }

  /* iOS zoomt bei Fokus, wenn Schrift < 16px — daher aufwerten */
  input[type=text], input[type=email], input[type=password], input[type=number],
  input[type=date], input[type=search], select, textarea { font-size: 16px; }

  /* Groessere Touch-Ziele */
  .btn { padding: 11px 16px; }
  .btn-sm { padding: 8px 13px; }
  .nav-link { padding: 12px 12px; }
  .tab { padding: 12px 13px; }

  /* Kanban: eine Spalte fast bildschirmbreit, angenehm zu wischen */
  .board { gap: 10px; }
  .col { flex-basis: 84vw; max-width: 340px; max-height: none; }

  /* Stat-Kacheln kompakter */
  .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tile .num { font-size: 1.45rem; }

  /* Winzige Phasen-Labels ausblenden — die farbigen Segmente bleiben */
  .phase-labels { display: none; }
  .order-head { padding: 16px; }

  /* Modals nutzen die volle Breite */
  .modal-bg { padding: 10px; align-items: flex-start; padding-top: 24px; }
  .modal { max-height: 92vh; }

  /* Klickbare Tabellenzeilen brauchen auf dem Handy mehr Luft */
  table.tbl td, table.tbl th { padding: 12px 10px; }
  .tscroll table.tbl { min-width: 540px; }
}
