/* ============================================================
   Tools Hub · The Woork — flat, esquinas redondeadas, Syne
   ============================================================ */
:root {
  --font: "Syne", -apple-system, BlinkMacSystemFont, "Helvetica Neue", system-ui, sans-serif;
  /* Gama */
  --pink: #f8b4d2;
  --lime: #c9f542;
  --green: #0a5a38;
  --yellow: #ffc531;
  --orange: #f28a18;
  --wine: #7b0b3c;
  --ink: #1f1e1b;
  --sand: #f6e2c3;
  --plum: #4b0e1f;
  /* Superficies */
  --bg: #fbf5ef;
  --surface: #fffdfa;
  --surface-2: #f4ece4;
  --line: #e6dbd0;
  --text: #1f1e1b;
  --text-2: #6b625b;
  --text-3: #a69b92;
  --accent: var(--green);
  --danger: #c8102e;
  --radius: 22px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1917;
    --surface: #242320;
    --surface-2: #2e2c28;
    --line: #3a3733;
    --text: #f6efe7;
    --text-2: #b8ada3;
    --text-3: #7d746c;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); font-weight: 400; color: var(--text); font-size: 14px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; overflow: hidden; background: var(--bg);
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3, h4, b, strong, .name, .tb-title, .auth-title { font-weight: 600; }
::selection { background: var(--pink); color: var(--plum); }

.wallpaper { position: fixed; inset: 0; z-index: 0; background: var(--bg); }

/* ---------- Login ---------- */
.auth {
  position: relative; z-index: 1; height: 100%; overflow-y: auto; display: flex; flex-direction: column;
  align-items: center; padding: 24px; gap: 18px;
}
.auth-card {
  margin-top: auto; width: min(420px, 100%); padding: 36px 34px 30px; border-radius: 28px;
  background: var(--surface); border: 1.5px solid var(--line);
  animation: pop .4s cubic-bezier(.2,.9,.25,1.1);
}
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 24px; }
.auth-logo {
  width: 72px; height: 72px; border-radius: 22.37%; display: grid; place-items: center;
  font-weight: 600; font-size: 28px; letter-spacing: -.02em; color: var(--pink); background: var(--wine);
}
.auth-title { font-size: 22px; letter-spacing: -.02em; }
.auth-title span { color: var(--text-2); font-weight: 400; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form h2 { margin: 0; font-size: 20px; letter-spacing: -.02em; }
.muted { color: var(--text-2); margin: 0; font-size: 13px; }
.question { margin: 4px 0 0; font-weight: 600; }
.auth-error { margin: 0; color: var(--danger); font-size: 13px; min-height: 1em; }
.auth-foot { position: relative; z-index: 1; color: var(--text-3); font-size: 12px; margin: 0 0 auto; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12px; color: var(--text-2); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 13px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--surface); outline: none; transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--orange); }
.field textarea { resize: vertical; min-height: 64px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.check input { accent-color: var(--green); width: 15px; height: 15px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 999px; font-weight: 600; font-size: 13px;
  background: var(--surface-2); color: var(--text); border: 1.5px solid transparent;
  transition: transform .1s, background .15s;
}
.btn:hover { background: var(--line); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--green); color: var(--lime); }
.btn.primary:hover { background: #0c6b43; }
.btn.danger { color: var(--wine); background: transparent; border-color: var(--line); }
.btn.danger:hover { background: var(--pink); color: var(--plum); border-color: transparent; }
.btn.small { padding: 5px 12px; font-size: 12px; }
.btn.block { width: 100%; padding: 12px; font-size: 14px; }
.btn:disabled { opacity: .55; cursor: default; }
.link { align-self: center; color: var(--orange); font-size: 13px; padding: 4px; }

/* ---------- Ventana ---------- */
.hub { position: relative; z-index: 1; height: 100%; padding: 24px; display: flex; }
.window {
  flex: 1; display: flex; flex-direction: column; min-height: 0; border-radius: var(--radius);
  background: var(--surface); border: 1.5px solid var(--line); overflow: hidden;
  animation: pop .35s cubic-bezier(.2,.9,.25,1.1);
}
.toolbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; height: 56px; border-bottom: 1.5px solid var(--line); }
.lights { display: flex; gap: 7px; margin-right: 8px; }
.lights span { width: 12px; height: 12px; border-radius: 50%; background: var(--orange); }
.lights span:nth-child(2) { background: var(--yellow); }
.lights span:nth-child(3) { background: var(--lime); }
.tb-btn { width: 32px; height: 28px; border-radius: 9px; display: grid; place-items: center; color: var(--text-2); }
.tb-btn:hover { background: var(--surface-2); }
.tb-title { font-size: 15px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search {
  margin-left: auto; display: flex; align-items: center; gap: 7px; padding: 0 12px; height: 32px; width: min(280px, 34vw);
  border-radius: 999px; background: var(--surface-2); color: var(--text-3); border: 1.5px solid transparent;
}
.search:focus-within { border-color: var(--orange); background: var(--surface); }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: none; color: var(--text); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.segmented { display: flex; padding: 3px; border-radius: 999px; background: var(--surface-2); }
.segmented button { width: 32px; height: 26px; border-radius: 999px; display: grid; place-items: center; color: var(--text-2); }
.segmented button.on { background: var(--ink); color: var(--sand); }
.avatar-btn { margin-left: 4px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 600;
  color: var(--plum); background: var(--pink);
}
.menu {
  position: absolute; right: 16px; top: 54px; z-index: 5; min-width: 230px; padding: 8px; border-radius: 18px;
  background: var(--surface); border: 1.5px solid var(--line); animation: pop .15s ease-out;
}
.menu-head { padding: 8px 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.menu-head small { color: var(--text-2); }
.menu button { display: block; width: 100%; text-align: left; padding: 8px 12px; border-radius: 12px; font-size: 13px; }
.menu button:hover { background: var(--green); color: var(--lime); }
.menu hr { border: 0; border-top: 1.5px solid var(--line); margin: 6px 4px; }

.body { flex: 1; display: flex; min-height: 0; position: relative; }
.sidebar {
  width: 216px; flex-shrink: 0; padding: 14px 12px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto;
  background: var(--surface-2); border-right: 1.5px solid var(--line); transition: margin .25s cubic-bezier(.2,.8,.2,1);
}
.sidebar.collapsed { margin-left: -218px; }
.sb-group { display: flex; flex-direction: column; gap: 3px; }
.sb-label { font-size: 12px; color: var(--text-3); padding: 0 12px 4px; }
.sb-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 999px; font-size: 13px; text-align: left; transition: background .12s; }
.sb-item i { font-style: normal; width: 16px; text-align: center; color: var(--orange); font-size: 12px; }
.sb-item:hover { background: var(--line); }
.sb-item.on { background: var(--ink); color: var(--sand); font-weight: 600; }
.sb-item.on i { color: var(--yellow); }
.sb-foot { margin-top: auto; padding: 0 12px; color: var(--text-3); font-size: 11px; }

.content { flex: 1; overflow-y: auto; padding: 24px 28px 40px; min-width: 0; }
.notice { margin-bottom: 18px; padding: 10px 12px 10px 16px; border-radius: 999px; background: var(--yellow); color: var(--plum); font-size: 13px; display: flex; gap: 12px; align-items: center; }
.notice .btn { background: var(--plum); color: var(--sand); }
.notice button:last-child { margin-left: auto; background: transparent; color: var(--plum); }
.empty { color: var(--text-3); text-align: center; margin: 80px 0; }

/* ---------- Iconos de app (flat) ---------- */
.app-icon {
  position: relative; flex-shrink: 0; border-radius: 22.37%; display: grid; place-items: center; overflow: hidden;
  background: var(--c, var(--green)); color: #fff; user-select: none; container-type: inline-size;
}
.app-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }
.app-icon .glyph { font-size: 48cqw; line-height: 1; }
.app-icon .glyph.txt { font-weight: 600; font-size: 34cqw; letter-spacing: -.02em; }
.app-icon.archived { filter: grayscale(1) opacity(.5); }

/* ---------- Cuadrícula ---------- */
.apps.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 14px; }
.apps.grid .app {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 20px 12px 18px;
  border-radius: 24px; background: var(--surface-2); border: 1.5px solid transparent; transition: border-color .15s, transform .15s;
}
.apps.grid .app:hover { border-color: var(--orange); }
.apps.grid .app:active { transform: scale(.98); }
.apps.grid .app .app-icon { width: 76px; height: 76px; transition: transform .2s cubic-bezier(.2,.9,.25,1.3); }
.apps.grid .app:hover .app-icon { transform: translateY(-2px) scale(1.04); }
.apps.grid .app .name { font-size: 14px; letter-spacing: -.01em; }
.apps.grid .app .desc { color: var(--text-2); font-size: 12px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.apps.grid .app .open, .apps.grid .app .meta .cat { display: none; }
.apps.grid .app .meta { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; }
.apps.grid .app .meta:not(:has(.tag)) { display: none; }

/* ---------- Lista ---------- */
.apps.list { display: flex; flex-direction: column; gap: 6px; }
.apps.list .app {
  display: grid; grid-template-columns: 46px 1fr auto; align-items: center; gap: 14px; padding: 10px 14px; border-radius: 20px; text-align: left;
  background: var(--surface-2); border: 1.5px solid transparent; transition: border-color .12s;
}
.apps.list .app:hover { border-color: var(--orange); }
.apps.list .app .app-icon { width: 46px; height: 46px; }
.apps.list .app .name { font-size: 14px; }
.apps.list .app .desc { color: var(--text-2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.apps.list .app .meta { display: flex; align-items: center; gap: 8px; }
.apps.list .app .cat { font-size: 12px; color: var(--text-3); }
.apps.list .app .open { padding: 5px 14px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--ink); color: var(--sand); }
.apps.list .app:hover .open { background: var(--green); color: var(--lime); }
.app { position: relative; text-decoration: none; color: inherit; }
.app .info { min-width: 0; display: flex; flex-direction: column; gap: 2px; }

.tag { font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--sand); color: var(--plum); }
.tag.admin { background: var(--wine); color: var(--pink); }
.tag.custom { background: var(--yellow); color: var(--plum); }
.tag.archived { background: var(--line); color: var(--text-2); }
.tag.ok { background: var(--lime); color: var(--green); }

/* ---------- Paneles de administración ---------- */
.panel { max-width: 960px; }
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.panel-head h2 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.panel-head p { margin: 2px 0 0; color: var(--text-2); font-size: 13px; }
.panel-head .btn { margin-left: auto; }
.rows { display: flex; flex-direction: column; gap: 6px; }
.row {
  display: grid; grid-template-columns: 22px 42px 1fr auto; align-items: center; gap: 12px; padding: 10px 14px;
  border-radius: 20px; background: var(--surface-2); border: 1.5px solid transparent; transition: border-color .12s;
}
.row:hover { border-color: var(--line); }
.row.dragging { opacity: .4; }
.row.over { border-color: var(--orange); }
.row .handle { cursor: grab; color: var(--text-3); font-size: 16px; text-align: center; }
.row .app-icon { width: 42px; height: 42px; }
.row .info b { font-size: 14px; display: block; }
.row .info b small { display: inline; color: var(--text-3); font-weight: 400; }
.row .info small { color: var(--text-2); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.row .avatar { width: 36px; height: 36px; font-size: 12px; }
.row.user { grid-template-columns: 42px 1fr auto; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }

/* ---------- Sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; display: grid; place-items: start center; padding-top: 60px; background: rgba(31,30,27,.35); overflow-y: auto; }
.sheet {
  width: min(580px, calc(100vw - 32px)); margin-bottom: 40px; border-radius: 28px; background: var(--surface);
  border: 1.5px solid var(--line); animation: sheet .25s cubic-bezier(.2,.9,.25,1.1);
}
@keyframes sheet { from { opacity: 0; transform: translateY(-16px) scale(.98); } }
.sheet-head { display: flex; align-items: center; padding: 20px 24px 10px; }
.sheet-head h3 { margin: 0; font-size: 19px; letter-spacing: -.02em; }
.sheet-head .x { margin-left: auto; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); font-size: 12px; color: var(--text-2); }
.sheet-head .x:hover { background: var(--pink); color: var(--plum); }
.sheet-body { padding: 6px 24px 24px; display: flex; flex-direction: column; gap: 12px; }
.sheet-body form { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.sheet-actions .left { margin-right: auto; }
.form-error { color: var(--danger); font-size: 13px; margin: 0; }
.icon-picker { display: flex; align-items: center; gap: 16px; }
.icon-picker .app-icon { width: 64px; height: 64px; }
.icon-picker .opts { display: flex; flex-direction: column; gap: 8px; font-size: 12px; color: var(--text-2); }
.icon-picker input[type=file] { font-size: 12px; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches button { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; }
.swatches button.on { border-color: var(--text); }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 12px; border-radius: 16px; background: var(--surface-2); max-height: 180px; overflow-y: auto; }
.code { padding: 12px 14px; border-radius: 16px; background: var(--sand); color: var(--plum); font-family: ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all; user-select: all; }
.hint { color: var(--text-2); font-size: 12px; margin: 0; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { padding: 9px 18px; border-radius: 999px; background: var(--ink); color: var(--sand); font-size: 13px; font-weight: 600; animation: pop .25s ease-out; }
.toast.err { background: var(--wine); color: var(--pink); }
.toast.ok { background: var(--green); color: var(--lime); }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .hub { padding: 0; }
  .window { border-radius: 0; border: 0; }
  .lights { display: none; }
  .tb-title { display: none; }
  .search { width: 100%; margin-left: 0; }
  .sidebar { position: absolute; z-index: 4; top: 0; bottom: 0; left: 0; }
  .sidebar.collapsed { margin-left: -240px; }
  .content { padding: 16px; }
  .apps.grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
  .apps.grid .app { padding: 14px 8px 12px; }
  .apps.grid .app .app-icon { width: 60px; height: 60px; }
  .apps.grid .app .desc { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .row { grid-template-columns: 22px 36px 1fr; }
  .row .actions { grid-column: 1 / -1; justify-content: flex-start; }
  .row.user { grid-template-columns: 36px 1fr; }
}
