* {
    box-sizing: border-box;
}

:root {
    --card: #16213e;
    --accent: #e94560;
    --fill: #0f3460;
    --border: #444;
    --muted: #aaa;
    --text: #eee;
    --column: 720px;
}

body {
    margin: 0;
    min-height: 100vh;
    padding: 1.5rem;
    background: #1a1a2e;
    color: var(--text);
    font-family: system-ui, sans-serif;
}

h1 {
    max-width: var(--column);
    margin: 0 auto 1.5rem;
    font-size: 2rem;
}

/* Auth and devices panel drawn as cards */
section {
    max-width: var(--column);
    margin: 0 auto 1.5rem;
    padding: 1.5rem 2rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
}

section h2 {
    margin: 0 0 1rem;
    font-size: 1.25rem;
}

input,
select {
    padding: 0.5rem 0.75rem;
    background: var(--fill);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
}

input::placeholder {
    color: var(--muted);
}

input:focus,
select:focus {
    outline: none;
    border-color: #888;
}

button,
.file-btn,
.tab {
    padding: 0.5rem 1.25rem;
    background: var(--fill);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
}

button:hover,
.file-btn:hover,
.tab:hover {
    background: #12386b;
    border-color: #888;
}

button:active,
.file-btn:active,
.tab:active {
    transform: scale(0.97);
}

/* File picker drawn as a button: the native input sits inside the label but is
   clipped out of sight (still focusable - Tab + Enter opens the dialog) */
.file-btn {
    display: inline-block; /* labels are display:inline, transform needs a box */
    line-height: 1.2;
}

.file-btn:focus-within {
    outline: none;
    border-color: #888;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

.file-name {
    color: var(--muted);
    font-size: 0.85rem;
    word-break: break-all;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th {
    text-align: left;
    color: var(--muted);
    font-weight: normal;
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 0.45rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid #2a2a4a;
}

.online  { color: #2ecc71; font-weight: bold; }
.offline { color: var(--muted); }
.error   { color: var(--accent); font-weight: bold; }
.busy    { color: #f39c12; }

/* Flash job statuses in the jobs table */
.pending  { color: var(--muted); }
.flashing { color: #f39c12; }
.done     { color: #2ecc71; font-weight: bold; }
.failed   { color: var(--accent); font-weight: bold; }

/* Compact destructive action in the devices table */
.device-del {
    padding: 0.15rem 0.6rem;
    color: var(--muted);
    font-size: 0.8rem;
    line-height: 1.2;
}

.device-del:hover {
    color: var(--accent);
    background: var(--fill);
    border-color: var(--accent);
}

.device-del:disabled {
    opacity: 0.5;
    cursor: default;
}

/* Click-to-rename device name */
.device-name {
    display: inline-block;
    padding: 0.1rem 0.3rem;
    margin: -0.1rem -0.3rem;
    border-radius: 4px;
    border-bottom: 1px dashed transparent;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.device-name:hover {
    background: var(--fill);
    border-bottom-color: var(--muted);
    color: #fff;
}

.device-name-input {
    width: 100%;
    padding: 0.15rem 0.35rem;
    font-size: inherit;
    font-family: inherit;
    border-color: #888;
    border-radius: 4px;
}

#msg { color: var(--muted); min-height: 1.2em; }
#jobs-msg { color: var(--muted); min-height: 1.2em; }
#auth-msg { min-height: 1.2em; }
#auth-msg.err { color: var(--accent); }

/* One-time token boxes (device token, personal api token) */
#new-token,
#api-token-box {
    margin: 0.75rem 0;
    padding: 0.75rem 1rem;
    background: var(--fill);
    border: 1px solid var(--border);
    border-radius: 6px;
}

#new-token p,
#api-token-box p {
    margin: 0.25rem 0;
}

.token-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

#new-token-value,
#api-token-value {
    padding: 0.35rem 0.6rem;
    background: #1a1a2e;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.85rem;
    word-break: break-all;
    user-select: all;
}

#copy-msg,
#copy-api-msg {
    color: #2ecc71;
    font-size: 0.85rem;
}

/* Tab bar under the heading - plain links styled like buttons */
.tabs {
    max-width: var(--column);
    margin: 0 auto 1.5rem;
    display: flex;
    gap: 0.5rem;
}

a.tab {
    display: inline-block;
    text-decoration: none;
}

.tab.active {
    border-color: var(--accent);
    background: var(--card);
    color: #fff;
}

/* API reference */
code,
pre {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

#api-panel code {
    color: #fff;
}

#api-panel h3 {
    margin: 1.4rem 0 0.6rem;
    font-size: 1rem;
    color: var(--muted);
}

.endpoint {
    margin: 0 0 0.75rem;
    padding: 0.75rem 1rem;
    background: #1a1a2e;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.endpoint p {
    margin: 0.4rem 0 0;
}

.ep-head {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0 0 0.2rem;
}

.ep-head code {
    font-size: 0.95rem;
}

.method {
    display: inline-block;
    min-width: 3.6rem;
    text-align: center;
    padding: 0.15rem 0.3rem;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: bold;
    letter-spacing: 0.03em;
}

.m-get    { color: #2ecc71; border: 1px solid #2ecc71; }
.m-post   { color: #f39c12; border: 1px solid #f39c12; }
.m-patch  { color: #5dade2; border: 1px solid #5dade2; }
.m-delete { color: var(--accent); border: 1px solid var(--accent); }

.auth-tag {
    color: var(--muted);
    font-size: 0.72rem;
    border: 1px solid var(--border);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}

#api-panel pre {
    margin: 0.6rem 0 0;
    padding: 0.6rem 0.75rem;
    background: #131326;
    border: 1px solid #2a2a4a;
    border-radius: 4px;
    font-size: 0.78rem;
    overflow-x: auto;
}

#api-panel pre.flow {
    margin-top: 0.75rem;
}