@layer reset, base, layout, components, responsive;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, p { margin: 0; }
  [hidden] { display: none !important; }
  img { max-width: 100%; }
}
@layer base {
  :root {
    color-scheme: light;
    --paper: #fff; --canvas: #f4f7f5; --ink: #182e29; --muted: #536a62;
    --line: #dce7e0; --accent: #17634b; --dark: #173b32; --mint: #e4f3eb;
    --amber: #785413; --warning: #fff3d5; --error: #a52c32; --danger: #fff0f0;
    --radius: 15px;
    font: 15px/1.55 "Segoe UI", Arial, sans-serif;
  }
  body { background: var(--canvas); color: var(--ink); }
  h1, h2, h3 { line-height: 1.2; letter-spacing: -.026em; }
  h1 { font-size: clamp(1.85rem, 4vw, 2.75rem); }
  h2 { font-size: 1.25rem; }
  h3 { font-size: 1.04rem; }
  a { color: var(--accent); text-underline-offset: 3px; }
  :focus-visible { outline: 3px solid #269c73; outline-offset: 3px; }
  input, select, textarea, button { font: inherit; color: inherit; }
  label { display: grid; align-content: start; gap: 5px; font-weight: 600; }
  input:not([type="checkbox"]), select, textarea {
    width: 100%; border: 1px solid #b9ccc2; background: var(--paper);
    border-radius: 8px; padding: .57rem .68rem; min-height: 41px; font-weight: 400;
  }
  textarea { resize: vertical; }
  button { cursor: pointer; }
  small, .subtle { color: var(--muted); }
  button:disabled { cursor: wait; opacity: .6; }
  code { overflow-wrap: anywhere; font-size: .92em; }
  .skip { position: absolute; z-index: 5; left: 1rem; top: 1rem; transform: translateY(-180%); background: var(--paper); padding: .6rem 1rem; border-radius: 6px; }
  .skip:focus { transform: none; }
}
@layer layout {
  .login { min-height: 100vh; padding: 1rem; display: grid; place-items: center; background: radial-gradient(ellipse at 75% 20%, #d7eee1, transparent 50%), linear-gradient(145deg,#f6faf7,#e8f0eb); }
  .login-card { width: min(100%, 460px); padding: clamp(1.5rem, 5vw, 2.7rem); background: var(--paper); border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 20px 60px #153b3018; }
  .login-card img { object-fit: contain; margin: 0 0 1.3rem; }
  .login-card h1 { margin: .35rem 0 .65rem; }
  .login-card p { color: var(--muted); }
  .login-card form { display: grid; gap: .9rem; margin-top: 1.5rem; }
  .login-card .kicker { color: var(--accent); }
  .login-card #login-error:empty { display: none; }
  .shell { min-height: 100vh; display: grid; grid-template-columns: 244px minmax(0, 1fr); }
  .sidebar { background: var(--dark); color: #e9f5ee; padding: 1rem .8rem; height: 100vh; overflow-y: auto; position: sticky; top: 0; scrollbar-color: #548372 var(--dark); }
  .brand { display: grid; gap: .4rem; justify-content: start; padding: .35rem .65rem .8rem; border-bottom: 1px solid #55776b; margin-bottom: .75rem; }
  .brand img { display: block; object-fit: contain; border-radius: 7px; background: #f8fbf9; padding: 4px 7px; }
  .brand span, .group-label { font-size: .67rem; font-weight: 700; letter-spacing: .1em; color: #c2d9ce; }
  .group-label { margin: .88rem .65rem .22rem; }
  .sidebar nav a { display: block; padding: .42rem .65rem; min-height: 35px; border-radius: 7px; color: #e5f1eb; text-decoration: none; font-size: .88rem; }
  .sidebar nav a:hover { background: #325b4d; }
  .sidebar nav a[aria-current="page"] { background: #e1f2e8; color: #1a4a3a; font-weight: 700; }
  .workspace { min-width: 0; position: relative; }
  .topbar { display: flex; justify-content: space-between; gap: .85rem; align-items: center; padding: .65rem clamp(1rem,4vw,2.25rem); border-bottom: 1px solid var(--line); background: var(--paper); min-height: 66px; }
  .top-start, .account { display: flex; align-items: center; gap: .7rem; }
  #crumb { color: var(--muted); font-size: .88rem; }
  .account { font-size: .88rem; }
  .account small { display: block; line-height: 1.2; }
  .account strong { overflow-wrap: anywhere; }
  .content { max-width: 1450px; padding: clamp(1rem, 4vw, 2.25rem); margin: 0 auto; }
  .view-header { display: flex; justify-content: space-between; align-items: end; gap: 1rem; margin-bottom: 1.15rem; }
  .view-header p { color: var(--muted); margin: .45rem 0 0; max-width: 65ch; }
  .view-body { display: grid; align-content: start; gap: 1rem; }
  .split { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 1rem; align-items: start; }
  .desk-split { grid-template-columns: minmax(240px, .85fr) minmax(0, 1.75fr); }
  .stack { display: grid; align-content: start; gap: .85rem; min-width: 0; }
  .form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: .8rem; }
  .form-grid .wide { grid-column: 1/-1; }
  .actions, .inline-form { display: flex; align-items: end; flex-wrap: wrap; gap: .55rem; }
  .inline-form label { flex: 1 1 160px; }
  .metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 155px), 1fr)); gap: .75rem; }
  .catalog { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr)); gap: .75rem; }
}
@layer components {
  .card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; min-width: 0; }
  .card > h2, .card > h3 { margin-bottom: .75rem; }
  .summary { background: linear-gradient(110deg,#e0f2e8,#f2f8f3 75%); padding: 1.3rem; }
  .summary h2 { font-size: 1.45rem; margin: .25rem 0 .3rem; }
  .summary p { max-width: 62ch; }
  .summary a { margin-top: .8rem; }
  .kicker { font-size: .7rem; font-weight: 750; letter-spacing: .12em; color: var(--accent); }
  .avatar { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--mint); color: #194b3b; font-weight: 750; }
  .primary, .secondary, .danger, .link-button {
    display: inline-flex; align-items: center; justify-content: center; min-height: 39px; border: 1px solid transparent;
    border-radius: 8px; padding: .45rem .78rem; font-weight: 650; text-decoration: none; white-space: normal;
  }
  .primary { background: var(--accent); color: #fff; }
  .primary:hover { background: #104e3a; }
  .secondary { background: var(--paper); color: var(--ink); border-color: #b9ccc2; }
  .secondary:hover { background: #edf5ef; }
  .topbar .nav-toggle { display: none; }
  .danger { color: var(--error); background: var(--danger); border-color: #e5bec0; }
  .link-button { color: var(--accent); background: transparent; justify-content: start; padding: .25rem 0; text-decoration: underline; text-underline-offset: 3px; }
  .metric { display: grid; align-content: start; gap: .16rem; }
  .metric strong { font-size: clamp(1.45rem, 3vw, 2rem); font-variant-numeric: tabular-nums; line-height: 1.2; }
  .metric p, .metric small { font-size: .87rem; }
  .status { background: var(--mint); color: #174e3a; font-weight: 650; font-size: .77rem; display: inline-block; border-radius: 999px; padding: .18rem .5rem; }
  .status.warn { background: var(--warning); color: var(--amber); }
  .status.off { background: #edf1ef; color: #40534a; }
  .error { color: var(--error) !important; }
  .toast { position: fixed; bottom: 1rem; right: 1rem; z-index: 4; max-width: min(30rem, calc(100% - 2rem)); padding: .7rem .95rem; border-radius: 8px; box-shadow: 0 7px 28px #18382a26; background: #163f32; color: #fff; }
  .toast:empty { display: none; }
  .toast.error { background: var(--danger); border: 1px solid #e5bec0; }
  .notice { border-left: 4px solid #70a28e; padding: .7rem .8rem; background: #f0f6f2; border-radius: 6px; }
  .table-scroll { overflow-x: auto; }
  table { width: 100%; border-collapse: collapse; text-align: left; font-size: .88rem; }
  th, td { padding: .65rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
  th { color: var(--muted); font-size: .8rem; }
  tr:last-child td { border-bottom: 0; }
  .rows { display: grid; margin: 0; padding: 0; list-style: none; }
  .rows li + li { border-top: 1px solid var(--line); }
  .row { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem .75rem; justify-content: space-between; padding: .65rem 0; }
  .row > div:first-child { min-width: min(115px,100%); overflow-wrap: anywhere; }
  .row button { min-height: 36px; }
  .row-header { display: flex; justify-content: space-between; align-items: start; flex-wrap: wrap; gap: .5rem; }
  .chat-log { display: grid; align-content: start; gap: .55rem; max-height: 56vh; overflow: auto; border-radius: 10px; background: #f3f7f4; padding: .65rem; }
  .message { min-width: 0; max-width: min(95%, 65ch); display: grid; gap: .3rem; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); padding: .6rem .7rem; }
  .message.user { justify-self: end; background: var(--mint); }
  .message p, .preserve { white-space: pre-wrap; overflow-wrap: anywhere; }
  .attachment { display: grid; gap: .5rem; justify-items: start; }
  .attachment img { object-fit: contain; border-radius: 7px; border: 1px solid var(--line); }
  .thumb { width: 100%; height: 125px; object-fit: contain; border-radius: 6px; background: #f7f9f7; }
  .chart { display: grid; gap: .5rem; }
  .chart-row { display: grid; grid-template-columns: minmax(70px, 45%) 1fr minmax(2ch, auto); align-items: center; gap: .5rem; font-size: .88rem; }
  meter { width: 100%; accent-color: var(--accent); }
  .field-note { font-size: .84rem; color: var(--muted); font-weight: 400; }
  .checkbox { display: flex; align-items: center; gap: .5rem; }
  .checkbox input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
}
@layer responsive {
  @media (max-width: 980px) { .shell { grid-template-columns: 200px minmax(0,1fr); } }
  @media (max-width: 790px) {
    .desk-split { grid-template-columns: 1fr; }
    .shell { display: block; }
    .sidebar { display: none; height: auto; max-height: 60vh; position: static; padding: .75rem 1rem; }
    .shell.nav-open .sidebar { display: block; }
    .sidebar nav { display: grid; grid-template-columns: repeat(auto-fit,minmax(140px,1fr)); gap: .85rem; }
    .topbar .nav-toggle { display: inline-flex; }
  }
  @media (max-width: 515px) {
    .split, .form-grid { grid-template-columns: 1fr; }
    .view-header { align-items: start; flex-direction: column; }
    .topbar { padding: .6rem .75rem; }
    .account { gap: .4rem; }
    .account .avatar, #crumb { display: none; }
    .content { padding: .85rem; }
    .card { padding: .8rem; }
  }
}
