/* ============================================================
   (주)더자란 관리시스템 — app.css
   시안 1b "운영 콕핏" 셸 + 컴포넌트 + 반응형.
   DESIGN.md §2–5의 구현. styles.css(토큰) 다음에 로드할 것.
   브레이크포인트: 1279 / 1023 / 767 (max-width)
   ============================================================ */

/* ---- base ---- */
body { margin: 0; background: var(--surface-alt); color: var(--text-body); font-family: var(--font-sans); }
* { box-sizing: border-box; }
:focus-visible { outline: none; box-shadow: var(--shadow-focus); border-radius: var(--radius-sm); }

/* ============ SHELL ============ */
.app { display: flex; min-height: 100vh; }
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---- sidebar (light) ---- */
.sidebar { width: 216px; flex-shrink: 0; background: var(--surface-card); border-right: 1px solid var(--border-subtle); display: flex; flex-direction: column; padding: 18px 12px 14px; }
.sidebar-logo { display: flex; align-items: center; gap: 9px; padding: 2px 8px 16px; }
.sidebar-logo-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--basil-50); border: 1px solid var(--basil-100); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar-logo-name { font-size: 13.5px; font-weight: 900; color: var(--ink-950); letter-spacing: -0.02em; line-height: 1; }
.sidebar-logo-sub { display: block; font-size: 8.5px; font-weight: 700; letter-spacing: 0.14em; color: var(--water-600); margin-top: 4px; }
.side-group-label { padding: 14px 12px 5px; font-size: 10px; font-weight: 700; letter-spacing: 0.13em; color: var(--ink-500); }
.side-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-md); color: var(--ink-700); font-size: 13.5px; font-weight: 500; text-decoration: none; cursor: pointer; transition: background var(--dur-fast, 140ms) var(--ease-soft, ease); }
.side-item:hover { background: var(--surface-sunken); }
.side-item.is-active { background: var(--basil-100); color: var(--basil-800); font-weight: 700; }
.side-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.sidebar-foot { margin-top: auto; padding: 11px 12px; border-radius: var(--radius-md); background: var(--surface-sunken); }
.sidebar-foot-label { font-size: 10.5px; color: var(--text-subtle); }
.sidebar-foot-value { font-size: 13px; font-weight: 800; color: var(--text-strong); margin-top: 3px; }

/* ---- topbar ---- */
.topbar { height: 58px; flex-shrink: 0; border-bottom: 1px solid var(--border-subtle); background: var(--surface-card); display: flex; align-items: center; gap: 14px; padding: 0 22px; }
.topbar-title { font-size: 17px; font-weight: 800; color: var(--ink-950); letter-spacing: -0.02em; }
.topbar-date { font-size: 12px; color: var(--text-muted); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 7px; }
.topbar-divider { width: 1px; height: 20px; background: var(--border-default); margin: 0 3px; }
.avatar { width: 29px; height: 29px; border-radius: 50%; background: var(--brand); color: var(--brand-contrast); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; }
.topbar-user { font-size: 12.5px; font-weight: 600; color: var(--text-body); }

/* ---- appbar + drawer (mobile) ---- */
.appbar { display: none; }
.scrim { display: none; }

/* ---- main grid ---- */
.main { padding: 18px 22px 24px; display: grid; grid-template-columns: 1fr 348px; gap: 16px; align-items: start; }
.main--single { grid-template-columns: minmax(0, 1080px); justify-content: center; }
.col-main { display: flex; flex-direction: column; min-width: 0; gap: 0; }
.col-rail { display: flex; flex-direction: column; gap: 12px; }

/* ============ COMPONENTS ============ */

/* ---- section header ---- */
.section-hd { display: flex; align-items: baseline; gap: 9px; margin: 20px 0 10px; }
.section-hd:first-child { margin-top: 0; }
.section-hd h2 { margin: 0; font-size: 15px; font-weight: 800; color: var(--text-strong); letter-spacing: -0.01em; }
.section-hd .caption { font-size: 11.5px; color: var(--text-subtle); font-weight: 500; }
.section-hd .action { margin-left: auto; }

/* ---- card ---- */
.card { background: var(--surface-card); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); box-shadow: var(--shadow-xs); padding: 14px 16px; }
.card--clickable { cursor: pointer; transition: transform 180ms var(--ease-soft, ease), box-shadow 180ms var(--ease-soft, ease); }
.card--clickable:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.card--critical { background: var(--critical-bg); border-color: oklch(0.582 0.166 28 / 0.28); }
.card--hero { position: relative; overflow: hidden; background: var(--basil-900); border: none; color: var(--paper); box-shadow: var(--shadow-sm); padding: 16px 18px; }
.card--hero .watermark { position: absolute; right: -16px; bottom: -22px; width: 90px; opacity: 0.10; pointer-events: none; }

/* ---- stat ---- */
.stat { display: flex; align-items: baseline; gap: 4px; }
.stat-num { font-size: 29px; font-weight: 900; color: var(--text-strong); letter-spacing: -0.03em; line-height: 1; }
.stat-unit { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.stat-num.is-critical { color: var(--critical); }
.card--hero .stat-num { font-size: 34px; color: #fff; }
.card--hero .stat-unit { color: var(--basil-200); }
.stat-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.stat-meta { font-size: 11px; color: var(--text-subtle); margin-top: 9px; }

/* ---- kv row ---- */
.kv { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border-subtle); }
.kv:last-child { border-bottom: none; }
.kv-label { font-size: 11.5px; color: var(--text-muted); }
.kv-value { font-size: 12.5px; font-weight: 700; color: var(--text-strong); }
.kv-value.is-critical { color: var(--critical); font-weight: 800; }
.kv-value.is-caution { color: var(--harvest-700); font-weight: 800; }

/* ---- badge ---- */
.badge { display: inline-flex; align-items: center; gap: 4px; height: 19px; padding: 0 8px; border-radius: var(--radius-pill); font-size: 10.5px; font-weight: 700; background: var(--ink-100); color: var(--ink-700); }
.badge .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge--brand { background: var(--basil-100); color: var(--basil-800); }
.badge--critical { background: #fff; color: var(--critical); }
.badge--caution { background: var(--caution-bg); color: var(--harvest-700); }
.badge--accent { background: var(--water-100); color: var(--water-800); }

/* ---- button ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 13px; border-radius: var(--radius-sm); font-size: 12.5px; font-weight: 700; font-family: inherit; border: none; background: none; color: var(--text-body); cursor: pointer; transition: filter 140ms ease, transform 140ms ease; }
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--brand); color: var(--brand-contrast); }
.btn--primary:hover { background: var(--brand-strong); }
.btn--secondary { background: var(--surface-card); border: 1px solid var(--border-default); }
.btn--secondary:hover { background: var(--surface-sunken); }
.btn--ghost { color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-sunken); }
.btn svg { width: 14px; height: 14px; }

/* ---- chip ---- */
.chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 11px; border-radius: var(--radius-pill); font-size: 12px; font-weight: 600; }
.chip b { font-weight: 800; }
.chip--basil { background: var(--basil-50); border: 1px solid var(--basil-100); color: var(--basil-800); }
.chip--water { background: var(--water-50); border: 1px solid var(--water-100); color: var(--water-800); }

/* ---- sensor row ---- */
.sensor { display: flex; align-items: center; gap: 9px; padding: 9px 0; border-bottom: 1px solid var(--border-subtle); }
.sensor:last-child { border-bottom: none; }
.sensor-icon { width: 27px; height: 27px; flex-shrink: 0; border-radius: 7px; display: flex; align-items: center; justify-content: center; }
.sensor-icon--ok { background: var(--water-100); color: var(--water-700); }
.sensor-icon--warn { background: var(--caution-bg); color: var(--harvest-700); }
.sensor-body { flex: 1; min-width: 0; }
.sensor-name { font-size: 12.5px; font-weight: 600; color: var(--text-body); }
.sensor-prev { font-size: 10.5px; color: var(--text-subtle); }
.sensor-value { font-size: 17px; font-weight: 800; letter-spacing: -0.02em; }
.sensor-value.is-ok { color: var(--water-700); }
.sensor-value.is-warn { color: var(--harvest-600); }

/* ---- table ---- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; color: var(--text-muted); padding: 10px 12px; border-bottom: 1px solid var(--border-default); }
.table td { font-size: 13px; color: var(--text-body); padding: 0 12px; height: 44px; border-bottom: 1px solid var(--border-subtle); }
.table tr:hover td { background: var(--surface-sunken); }
.table .num { text-align: right; font-family: var(--font-mono); font-size: 12.5px; }
.table-scroll { overflow-x: auto; }
.table-scroll .table th:first-child, .table-scroll .table td:first-child { position: sticky; left: 0; background: var(--surface-card); }

/* ---- input ---- */
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-body); margin-bottom: 6px; }
.input { width: 100%; height: 36px; padding: 0 12px; border: 1.5px solid var(--border-default); border-radius: var(--radius-md); font-size: 13.5px; font-family: inherit; color: var(--text-strong); background: var(--surface-card); }
.input::placeholder { color: var(--text-subtle); }
.input:focus { outline: none; border-color: var(--focus-ring); box-shadow: var(--shadow-focus); }
.input.is-error { border-color: var(--critical); }

/* ---- empty / skeleton ---- */
.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 36px 16px; color: var(--text-muted); font-size: 13px; text-align: center; }
.skeleton { border-radius: var(--radius-sm); background: var(--surface-sunken); animation: skel 1.2s ease-in-out infinite; }
@keyframes skel { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* ============ RESPONSIVE ============ */

/* laptop ≤1279 */
@media (max-width: 1279px) {
  .main { grid-template-columns: 1fr 320px; }
}

/* tablet ≤1023: icon rail + rail merges into main top */
@media (max-width: 1023px) {
  .sidebar { width: 64px; padding: 14px 8px; align-items: center; }
  .sidebar-logo { padding: 2px 0 14px; }
  .sidebar-logo-name, .sidebar-logo-sub, .side-group-label, .sidebar-foot { display: none; }
  .side-item { justify-content: center; padding: 12px; width: 44px; }
  .side-item .label { display: none; }
  .main { grid-template-columns: 1fr; }
  .col-rail { order: -1; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .col-rail > .rail-span { grid-column: 1 / -1; }
}

/* mobile ≤767: appbar + drawer, single column */
@media (max-width: 767px) {
  .appbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: var(--z-sticky); height: 56px; padding: 0 8px 0 4px; background: var(--surface-card); border-bottom: 1px solid var(--border-subtle); }
  .appbar-menu, .appbar-more { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; border: none; background: none; color: var(--text-body); border-radius: var(--radius-md); }
  .appbar-title { font-size: 14.5px; font-weight: 800; color: var(--ink-950); letter-spacing: -0.02em; margin-right: auto; }

  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: var(--z-overlay); width: 280px; padding: 18px 12px; align-items: stretch; transform: translateX(-100%); transition: transform 240ms var(--ease-soft, ease); box-shadow: var(--shadow-xl); }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-logo-name, .sidebar-logo-sub, .side-group-label, .sidebar-foot { display: block; }
  .sidebar-logo { display: flex; padding: 2px 8px 16px; }
  .side-item { justify-content: flex-start; width: auto; min-height: 44px; padding: 10px 12px; }
  .side-item .label { display: inline; }
  .scrim.is-on { display: block; position: fixed; inset: 0; z-index: calc(var(--z-overlay) - 1); background: oklch(0.205 0.014 158 / 0.45); }
  body.drawer-open { overflow: hidden; }

  .topbar { height: auto; flex-wrap: wrap; gap: 8px; padding: 12px 16px; }
  .topbar-right { width: 100%; margin-left: 0; }
  .topbar .btn--util { display: none; } /* 유틸은 오버플로 메뉴/드로어로 */

  .main { padding: 14px 16px 24px; grid-template-columns: 1fr; gap: 12px; }
  .col-rail { order: -1; display: flex; flex-direction: column; gap: 12px; }
  .card { padding: 16px; }
  .btn { height: 44px; padding: 0 16px; font-size: 13.5px; }
  .input { height: 44px; }
  .stat-num { font-size: 28px; }
  .card--hero .stat-num { font-size: 32px; }
  /* grid helpers: 3-up/2-up sections collapse */
  .grid-3, .grid-2 { grid-template-columns: 1fr !important; }
}

/* desktop grid helpers */
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 1023px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
