/* Layout (Section 12): containers, grids, tables, navigation, sidebar. Mobile first. */

/* Containers (12.2) */
.wrap{max-width:560px;margin:0 auto;padding:16px}
@media (min-width:400px){.wrap{padding:20px}}
.main{display:block;overflow-x:clip}
.main-wide{display:block;overflow-x:clip;max-width:1180px;margin:0 auto;padding:20px 16px}
@media (min-width:960px){.main-wide{padding:28px 32px}}
.screen{display:flex;flex-direction:column;gap:14px;min-width:0}
.has-bottom-nav{padding-bottom:calc(96px + env(safe-area-inset-bottom))}
.has-bottom-nav-sm{padding-bottom:calc(84px + env(safe-area-inset-bottom))}
body{min-height:100vh;min-height:100dvh}

/* Grid rules (12.3) */
.grid-2{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}
.span-2{grid-column:1 / -1}
.kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,170px),1fr));gap:12px}
.cols{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,340px),1fr));gap:16px;align-items:start}
@media (max-width:359px){.grid-2{grid-template-columns:1fr}}
.form-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,240px),1fr));gap:14px}

/* Student app bar (12.7) */
.appbar{background:transparent}
.appbar-in{display:flex;align-items:center;justify-content:space-between;gap:12px;max-width:560px;margin:0 auto;padding:18px 16px 8px}
@media (min-width:400px){.appbar-in{padding-left:20px;padding-right:20px}}
.appbar-in > :first-child{min-width:0;flex:1 1 auto}
.appbar .label{margin-bottom:4px}
.page-title{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
.round-btn{flex:none;display:inline-flex;align-items:center;justify-content:center;width:48px;height:48px;border:var(--b2w) solid currentColor;border-radius:50%;color:inherit;text-decoration:none;background:transparent}
[data-theme="brutal"] .round-btn{background:#FFFFFF;border-color:#111111;box-shadow:3px 3px 0 #111111}
[data-theme="shelf"] .appbar.band-k1{background:#B5452F;color:#FFFFFF}
[data-theme="shelf"] .appbar.band-k2{background:#2F5D46;color:#FFFFFF}
[data-theme="shelf"] .appbar.band-k3{background:#E0A526;color:#1E1E1C}
[data-theme="shelf"] .appbar.band-k4{background:#233A73;color:#FFFFFF}
[data-theme="shelf"] .appbar .label{color:inherit}

/* Responsive tables (12.5) */
.table{display:flex;flex-direction:column;gap:10px}
.tr{display:grid;grid-template-columns:1fr 1fr;gap:6px 12px;padding:14px 16px;background:var(--surface);border:var(--card-border);border-radius:var(--r);box-shadow:var(--card-shadow)}
.tr > [role="cell"]::before{content:attr(data-label);display:block;font-size:12px;font-weight:600;color:var(--muted)}
.tr > [role="cell"]:first-child{grid-column:1 / -1;font-weight:700}
.tr > [role="cell"]:first-child::before{display:none}
.tr.th{display:none}
.tr > [role="cell"].cell-actions{grid-column:1 / -1}
.tr > [role="cell"].cell-actions::before{display:none}
@media (min-width:700px){
  .table{gap:0;background:var(--surface);border:var(--card-border);border-radius:var(--r);box-shadow:var(--card-shadow)}
  .tr{grid-template-columns:var(--cols);align-items:center;background:none;border:0;border-bottom:var(--divider);border-radius:0;box-shadow:none}
  .tr:last-child{border-bottom:0}
  .tr.th{display:grid;font-size:12px;font-weight:600;color:var(--muted)}
  .tr > [role="cell"]::before{display:none}
  .tr > [role="cell"]:first-child{grid-column:auto}
  .tr > [role="cell"].cell-actions{grid-column:auto}
  .two-col{display:grid;grid-template-columns:minmax(0,1fr) 340px;gap:16px;align-items:start}
}

/* Navigation (12.6) */
.bottom-nav{position:fixed;left:0;right:0;bottom:0;z-index:20;background:var(--nav-bg);border-top:1px solid var(--line);padding-bottom:env(safe-area-inset-bottom)}
.tabs{display:flex;justify-content:space-around;align-items:flex-end;max-width:560px;margin:0 auto;padding:6px 6px 8px}
.tab{flex:1 1 0;min-width:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;min-height:54px;color:var(--muted);text-decoration:none;font-size:12px;font-weight:600}
.tab-ic{display:flex;align-items:center;justify-content:center;width:52px;height:30px;border-radius:15px}
.tab[aria-current="page"]{color:var(--text);font-weight:800}
.plank{display:none}
body:has(:is(input,select,textarea):focus) .bottom-nav{display:none}

/* Bento */
[data-theme="bento"] .tab[aria-current="page"]{color:#4B32C9}
[data-theme="bento"] .tab[aria-current="page"] .tab-ic{background:#ECE9FF}
/* Soft brutalism */
[data-theme="brutal"] .bottom-nav{border-top:2px solid #111111}
[data-theme="brutal"] .tab{margin:0 2px;border:2px solid transparent;border-radius:12px;color:#111111}
[data-theme="brutal"] .tab[aria-current="page"]{background:#FFD43B;border-color:#111111}
/* Index card: divider tabs */
[data-theme="index"] .tabs{gap:5px;padding:10px 10px 0;height:74px}
[data-theme="index"] .tab{height:50px;min-height:0;justify-content:flex-start;padding-top:12px;border-radius:10px 10px 0 0;background:var(--tab-c);color:#1C2B4A;transition:height .22s ease}
[data-theme="index"] .tab[aria-current="page"]{height:64px;background:#FFFFFF}
[data-theme="index"] .tab-ic{display:none}
/* Bookshelf: book spines */
[data-theme="shelf"] .bottom-nav{border-top:0;padding:0 12px calc(12px + env(safe-area-inset-bottom))}
[data-theme="shelf"] .tabs{justify-content:center;gap:6px;height:96px;padding:0}
[data-theme="shelf"] .tab{flex:1 1 0;max-width:64px;height:70px;min-height:0;border-radius:4px 4px 0 0;background:var(--tab-s);color:var(--tab-s-fg);transition:height .32s cubic-bezier(.3,1.5,.5,1)}
[data-theme="shelf"] .tab[aria-current="page"]{height:92px;color:var(--tab-s-fg)}
[data-theme="shelf"] .tab-ic{display:none}
[data-theme="shelf"] .tab-tx{writing-mode:vertical-rl;transform:rotate(180deg);font-size:12px;font-weight:800;text-transform:uppercase;letter-spacing:.04em;max-height:62px;overflow:hidden}
[data-theme="shelf"] .plank{display:block;max-width:560px;height:10px;margin:0 auto;border-radius:2px;background:#7A5A40}
/* The count dot sits on the tab itself so it stays visible in every theme */
.tab{position:relative}
.tab .dot{top:2px;right:calc(50% - 30px)}
[data-theme="index"] .tab .dot,[data-theme="shelf"] .tab .dot{top:4px;right:4px}

/* Owner and admin top bar on phones */
.topbar{display:flex;align-items:center;justify-content:space-between;gap:12px;min-height:56px;padding:6px 16px;background:var(--nav-bg);border-bottom:1px solid var(--line)}
[data-theme="brutal"] .topbar{border-bottom:2px solid #111111}
.topbar-name{font-family:var(--font-display);font-weight:var(--dw);letter-spacing:var(--track);font-size:18px;min-width:0;overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
.topbar .round-btn{width:44px;height:44px;border:0}

/* Sidebar (desktop owner and admin) */
.side{display:none}
.col{min-width:0}
@media (min-width:960px){
  .shell{display:grid;grid-template-columns:240px minmax(0,1fr);min-height:100vh;min-height:100dvh}
  .side{display:flex;flex-direction:column;gap:20px;position:sticky;top:0;height:100vh;height:100dvh;overflow-y:auto;padding:22px 14px;background:var(--side-bg);color:var(--side-fg)}
  .bottom-nav,.topbar{display:none}
  .has-bottom-nav,.has-bottom-nav-sm{padding-bottom:0}
}
.side-brand{display:flex;flex-direction:column;gap:2px;padding:0 6px}
.side-brand .brand{font-size:18px}
.side-lib{font-size:13px;font-weight:600}
.side-nav{display:flex;flex-direction:column;gap:6px;flex:1 1 auto}
.side-item{display:flex;align-items:center;gap:10px;min-height:44px;padding:0 12px;border-radius:10px;color:inherit;text-decoration:none;font-weight:600;background:none;border:0;font:inherit;font-weight:600;cursor:pointer;text-align:left;width:100%}
.side-item[aria-current="page"]{font-weight:800}
.side-foot{display:flex;flex-direction:column;gap:6px}
[data-theme="index"] .side{padding-left:0}
[data-theme="index"] .side-item{width:88%;border-radius:0 10px 10px 0;background:var(--tab-c)}
[data-theme="index"] .side-item{transition:width .2s ease}
[data-theme="index"] .side-item[aria-current="page"]{width:100%;background:#FFFFFF}
[data-theme="index"] .side-foot .side-item{background:transparent}
[data-theme="bento"] .side-item[aria-current="page"]{background:#ECE9FF;color:#4B32C9}
[data-theme="brutal"] .side{border-right:2px solid #111111}
[data-theme="brutal"] .side-item{border:2px solid transparent}
[data-theme="brutal"] .side-item[aria-current="page"]{background:#FFD43B;border-color:#111111;box-shadow:3px 3px 0 #111111}
[data-theme="shelf"] .side-item{border-left:8px solid var(--tab-s);border-radius:3px;transition:transform .25s cubic-bezier(.3,1.5,.5,1)}
[data-theme="shelf"] .side-item[aria-current="page"]{background:#3A3A36;color:#FFFFFF;transform:translateX(8px)}
[data-theme="shelf"] .side-foot .side-item{border-left-color:transparent}
.side .brand{color:inherit}
