/* ============================================================================
   TCOCube — QuickBooks connection tool.
   Clean, modern fintech UI. Restrained surfaces; the connection schematic is
   the one expressive element. Colour carries meaning: cobalt = action,
   signal-green = connected, alert-red = failed.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=IBM+Plex+Sans:ital,wght@0,400;0,500;0,600;1,400&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
    --ink:        #0d1220;
    --ink-2:      #1c2333;
    --slate:      #5b6577;
    --slate-2:    #8a93a3;
    --canvas:     #f7f8fa;
    --surface:    #ffffff;
    --line:       #e6e9ee;
    --line-2:     #d4d9e1;

    --cobalt:     #2f6bff;
    --cobalt-700: #1f4fd6;
    --cobalt-050: #eef3ff;
    --signal:     #10b981;
    --signal-050: #e7f7f1;
    --alert:      #e5484d;
    --alert-050:  #fdeced;

    --display: 'Space Grotesk', system-ui, sans-serif;
    --body:    'IBM Plex Sans', system-ui, -apple-system, sans-serif;
    --mono:    'IBM Plex Mono', ui-monospace, 'Cascadia Code', monospace;

    --shadow-sm: 0 1px 2px rgba(13,18,32,.06), 0 1px 1px rgba(13,18,32,.04);
    --shadow-md: 0 1px 3px rgba(13,18,32,.08), 0 12px 28px -14px rgba(13,18,32,.30);
    --radius:    14px;
    --radius-sm: 10px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--body);
    font-size: 16px;
    line-height: 1.6;
    color: var(--ink);
    background-color: var(--canvas);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* --- Page armatures ------------------------------------------------------- */

.stage {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2.5rem 1.25rem;
}

.console {
    max-width: 880px;
    margin: 0 auto;
    padding: 1.6rem 1.25rem 4rem;
}

/* --- Surfaces ------------------------------------------------------------- */

.panel {
    position: relative;
    width: 100%;
    max-width: 480px;
    padding: 2.2rem 2.1rem 2.3rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

/* --- Type ----------------------------------------------------------------- */

.plate {
    font-family: var(--display);
    font-weight: 700;
    line-height: 1.12;
    letter-spacing: -.02em;
    color: var(--ink);
    margin: 0;
}
.plate--xl { font-size: clamp(1.9rem, 5vw, 2.5rem); }
.plate--lg { font-size: clamp(1.45rem, 4vw, 1.9rem); }
.plate--sm { font-size: 1.15rem; font-weight: 600; }

/* Mono eyebrow — the structural label: this is a data/connection product. */
.stamp {
    font-family: var(--mono);
    font-weight: 500;
    font-size: .72rem;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--slate);
}
.stamp.accent { color: var(--cobalt); }

.rule {
    height: 0;
    border: 0;
    border-top: 1px solid var(--line);
    margin: 1.6rem 0;
}

.lede {
    color: var(--slate);
    font-size: 1.02rem;
    margin: .7rem 0 0;
}
.lede strong, .lede em { color: var(--ink); font-style: normal; font-weight: 600; }

/* --- Grouped field section (login keys) ----------------------------------- */

.ledger {
    background: var(--canvas);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 1.3rem 1.2rem;
}

.field { display: block; margin: 1rem 0; text-align: left; }
.field:first-child { margin-top: 0; }
.field:last-child { margin-bottom: 0; }
.field > .stamp { display: block; margin-bottom: .4rem; color: var(--slate); }

input[type="password"],
input[type="text"],
input[type="email"] {
    width: 100%;
    padding: .7rem .85rem;
    font-family: var(--body);
    font-size: 1rem;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    transition: border-color .15s ease, box-shadow .15s ease;
}
input::placeholder { color: var(--slate-2); }
input:focus {
    outline: none;
    border-color: var(--cobalt);
    box-shadow: 0 0 0 3px rgba(47,107,255,.18);
}

/* --- Buttons -------------------------------------------------------------- */

.lever, .btn {
    display: inline-block;
    font-family: var(--body);
    font-weight: 600;
    font-size: .95rem;
    letter-spacing: 0;
    text-decoration: none;
    color: #fff;
    cursor: pointer;
    padding: .68rem 1.3rem;
    border: 1px solid var(--cobalt-700);
    border-radius: var(--radius-sm);
    background: var(--cobalt);
    box-shadow: var(--shadow-sm);
    transition: background .15s ease, transform .08s ease, box-shadow .15s ease;
}
.lever:hover, .btn:hover { background: var(--cobalt-700); }
.lever:active, .btn:active { transform: translateY(1px); }

.lever--xl { width: 100%; text-align: center; font-size: 1rem; padding: .85rem 1.5rem; }

.btn-ghost {
    font-family: var(--body);
    font-weight: 500;
    font-size: .85rem;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-2);
    border-radius: 8px;
    padding: .45rem .85rem;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.btn-ghost:hover { background: var(--canvas); border-color: var(--slate-2); }
.btn-ghost.danger { color: var(--alert); }
.btn-ghost.danger:hover { background: var(--alert-050); border-color: var(--alert); }

.link-quiet { color: var(--cobalt); text-decoration: none; font-weight: 500; }
.link-quiet:hover { text-decoration: underline; }

/* ============================================================================
   SIGNATURE — the connection schematic.
   [ QuickBooks ] ——•—— [ TCOCube ], stateful: pending / established / interrupted.
   ========================================================================== */

.link-diagram {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: clamp(.5rem, 5vw, 1.5rem);
    margin: 0 auto 1.6rem;
    max-width: 360px;
}

.node { display: flex; flex-direction: column; align-items: center; gap: .55rem; width: 84px; flex-shrink: 0; }
.node-icon {
    width: 56px; height: 56px;
    display: grid; place-items: center;
    background: var(--surface);
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    color: var(--ink-2);
    transition: border-color .25s ease, color .25s ease;
}
.node-icon svg { width: 28px; height: 28px; }
.node-label {
    font-family: var(--mono);
    font-size: .68rem;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--slate);
}

/* The wire sits between the two icons; its centre aligns with the 56px icons. */
.wire { position: relative; flex: 1; height: 56px; min-width: 56px; }
.wire-line {
    position: absolute; top: 28px; left: 0; right: 0; height: 0;
    border-top: 2px dashed var(--line-2);
}
.wire-dot {
    position: absolute; top: 28px; left: 8%;
    width: 8px; height: 8px; margin: -4px 0 0 -4px;
    border-radius: 50%; background: var(--cobalt);
    box-shadow: 0 0 0 4px rgba(47,107,255,.16);
    opacity: 0;
}
.wire-badge {
    position: absolute; top: 28px; left: 50%;
    transform: translate(-50%, -50%);
    width: 26px; height: 26px;
    display: grid; place-items: center;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--line-2);
    color: var(--cobalt);
}
.wire-badge svg { width: 14px; height: 14px; }

/* Pending — a pulse travels toward TCOCube. */
@keyframes wire-travel {
    0%   { left: 6%;  opacity: 0; }
    18%  { opacity: 1; }
    82%  { opacity: 1; }
    100% { left: 94%; opacity: 0; }
}
.link-diagram.is-pending .wire-dot { animation: wire-travel 1.9s cubic-bezier(.45,0,.55,1) infinite; }

/* Established — solid green, check badge pops in, nodes light up. */
.link-diagram.is-established .wire-line { border-top-style: solid; border-top-color: var(--signal); }
.link-diagram.is-established .wire-badge { background: var(--signal); border-color: var(--signal); color: #fff; }
.link-diagram.is-established .node-icon { border-color: var(--signal); color: var(--signal); }
@keyframes badge-pop {
    0%   { transform: translate(-50%, -50%) scale(.4); opacity: 0; }
    70%  { transform: translate(-50%, -50%) scale(1.12); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
.link-diagram.is-established .wire-badge { animation: badge-pop .5s cubic-bezier(.2,.8,.2,1) both; }

/* Interrupted — the line breaks at the badge, red ✕. */
.link-diagram.is-interrupted .wire-line { border-top-color: var(--alert); }
.link-diagram.is-interrupted .wire-badge { background: var(--alert); border-color: var(--alert); color: #fff; }
/* mask a gap around the badge so the line reads as broken */
.link-diagram.is-interrupted .wire::before,
.link-diagram.is-interrupted .wire::after {
    content: ""; position: absolute; top: 26px; height: 6px; width: 18px; background: var(--surface); z-index: 1;
}
.link-diagram.is-interrupted .wire::before { left: calc(50% - 22px); }
.link-diagram.is-interrupted .wire::after  { left: calc(50% + 4px); }

/* Status caption under the schematic. */
.diagram-read { text-align: center; margin: 0 0 1.4rem; }
.diagram-read .state-label {
    font-family: var(--mono);
    font-size: .72rem;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--slate);
}
.diagram-read .state-label.established { color: var(--signal); }
.diagram-read .state-label.interrupted { color: var(--alert); }

/* ============================================================================
   App shell (home / admin)
   ========================================================================== */

.appbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .2rem 0 1.1rem;
    border-bottom: 1px solid var(--line);
    margin-bottom: 2.2rem;
}
.brand { display: flex; align-items: center; gap: .6rem; }
.brand .cube { width: 26px; height: 26px; color: var(--cobalt); }
.brand-name { font-family: var(--display); font-weight: 700; font-size: 1.1rem; letter-spacing: -.01em; color: var(--ink); }
.brand-sub { font-family: var(--mono); font-size: .74rem; color: var(--slate-2); }
.brand-sub::before { content: "/"; margin: 0 .5rem 0 .35rem; color: var(--line-2); }
.appbar-nav { display: flex; gap: .5rem; align-items: center; }

.page-head { margin-bottom: 1.8rem; }
.page-head .plate { margin-bottom: .35rem; }
.page-head .lede { margin-top: .2rem; }

.counter {
    display: inline-flex;
    align-items: baseline;
    gap: .6rem;
}
.counter .num { font-family: var(--display); font-weight: 700; font-size: 2.2rem; line-height: 1; color: var(--ink); }
.counter .stamp { color: var(--slate); }

.module {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.5rem 1.5rem;
    margin-bottom: 1.4rem;
    box-shadow: var(--shadow-sm);
}
.module h3 { margin: 0 0 1.1rem; }

.tile { display: flex; align-items: center; justify-content: space-between; gap: 1rem; text-decoration: none; color: var(--ink); transition: border-color .15s ease, box-shadow .15s ease; }
.tile:hover { border-color: var(--line-2); box-shadow: var(--shadow-md); }
.tile .tile-arrow { color: var(--cobalt); font-size: 1.3rem; flex-shrink: 0; }
.tile p { margin: .3rem 0 0; color: var(--slate); font-size: .95rem; }

.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.row input { flex: 1; min-width: 180px; }

/* Client connection rows */
.entry { border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: .8rem; overflow: hidden; background: var(--surface); }
.entry:last-child { margin-bottom: 0; }
.entry-head {
    display: flex; justify-content: space-between; align-items: center; gap: 1rem;
    padding: .85rem 1.1rem;
    border-bottom: 1px solid var(--line);
    background: var(--canvas);
}
.entry-name { font-family: var(--display); font-weight: 600; font-size: 1.05rem; color: var(--ink); }
.entry-actions { display: flex; gap: .4rem; flex-shrink: 0; }
.entry-body { padding: 1rem 1.1rem; }

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}
.detail .stamp { display: block; margin-bottom: .25rem; }
.detail .v { font-size: .95rem; color: var(--ink); word-break: break-word; }

.link-cell { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.token-link {
    font-family: var(--mono);
    font-size: .8rem;
    background: var(--canvas);
    color: var(--slate);
    padding: .5rem .6rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    word-break: break-all;
    flex: 1;
    min-width: 200px;
}
a.token-link {
    color: var(--cobalt);
    text-decoration: none;
    transition: background .15s ease, border-color .15s ease;
}
a.token-link:hover { text-decoration: underline; background: var(--cobalt-050); border-color: rgba(47,107,255,.3); }

.muted { color: var(--slate); }

.edit-form { display: none; gap: .6rem; flex-wrap: wrap; align-items: center; padding: 1rem 1.1rem 1.2rem; }
.edit-form.open { display: flex; }
.entry.editing .entry-body { display: none; }

.note { text-align: center; }
.note-error {
    margin-top: 1rem;
    font-size: .9rem;
    color: var(--alert);
    background: var(--alert-050);
    border: 1px solid rgba(229,72,77,.3);
    border-radius: var(--radius-sm);
    padding: .7rem .85rem;
    text-align: left;
}

/* --- Quality floor -------------------------------------------------------- */

:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; }

@media (max-width: 600px) {
    .panel { padding: 1.8rem 1.4rem 2rem; }
    .appbar { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
    .link-diagram.is-pending .wire-dot { animation: none; opacity: 1; left: 50%; }
    .link-diagram.is-established .wire-badge { animation: none; }
}
