/* Knox Device Checker - Foxway brand palette.
   Status colours are semantic: green = clean, pink = locked by us,
   dark red = locked by another reseller or error. */

:root {
    --dark-purple: #420070;
    --purple: #8B4DFF;
    --coral: #FF4A57;
    --green: #71EEA2;
    --dark-red: #B90047;
    --light-purple: #D1D0FB;
    --pink: #F8D2D9;

    --page-bg: #F6F5FC;
    --card-bg: #ffffff;
    --text: #22103B;
    --text-muted: #6B6480;
    --border: #E7E4F7;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 8px rgba(66, 0, 112, 0.06);
    --shadow-lg: 0 12px 32px rgba(66, 0, 112, 0.16);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

[hidden] { display: none !important; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--page-bg);
    color: var(--text);
    min-height: 100vh;
}

/* ==================== App bar ==================== */

/* Scrolls with the page by design - the bar is branding, not a toolbar.
   The account dropdown anchors to .user-menu, not to the bar. */
.app-bar {
    background: var(--dark-purple);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 1px 3px rgba(66, 0, 112, 0.18);
}

/* Full width, unlike .container, so the avatar sits at the screen edge.
   Three columns rather than space-between: the empty first column balances
   the avatar in the third, centring the brand against the whole bar. */
.app-bar-inner {
    padding: 15px 24px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
}

.brand {
    grid-column: 2;
    justify-self: center;
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.brand-logo {
    width: 52px;
    height: 52px;
    border-radius: 11px;
    flex-shrink: 0;
    display: block;
}

.brand-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.brand-title {
    color: #fff;
    font-size: 1.7em;
    font-weight: 700;
    letter-spacing: 0.2px;
    white-space: nowrap;
}

.brand-subtitle {
    color: var(--light-purple);
    font-size: 0.92em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==================== Avatar and account menu ==================== */

.user-menu {
    grid-column: 3;
    justify-self: end;
    position: relative;   /* anchors the dropdown */
    flex-shrink: 0;
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid transparent;
    background: var(--coral);
    color: #fff;
    font-size: 0.95em;
    font-weight: 700;
    letter-spacing: 0.5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s, transform 0.2s;
}
.avatar:hover { transform: scale(1.05); }
.avatar:focus-visible { outline: none; border-color: var(--light-purple); }
.avatar[aria-expanded="true"] { border-color: #fff; }

.user-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    min-width: 240px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    z-index: 60;
}

.user-dropdown-identity {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.user-dropdown-name { font-weight: 600; font-size: 0.95em; }
.user-dropdown-email {
    font-size: 0.85em;
    color: var(--text-muted);
    word-break: break-all;
}

.user-dropdown-item {
    display: block;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    text-align: left;
    font-size: 0.95em;
    font-weight: 600;
    color: var(--dark-red);
    cursor: pointer;
    transition: background 0.2s;
}
.user-dropdown-item:hover { background: var(--pink); }

/* ==================== Layout ==================== */

.container { max-width: 1400px; margin: 0 auto; padding: 24px 20px 48px; }

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.card h2 {
    font-size: 1.2em;
    color: var(--dark-purple);
    margin-bottom: 18px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 968px) { .grid-2 { grid-template-columns: 1fr; } }

/* ==================== Forms ==================== */

.form-group { margin-bottom: 20px; }
label { display: block; font-weight: 600; margin-bottom: 8px; color: var(--text); }

input[type="text"], select, textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text);
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--purple);
    box-shadow: 0 0 0 3px rgba(139, 77, 255, 0.15);
}

textarea { font-family: 'Courier New', monospace; resize: vertical; min-height: 150px; }

/* ==================== Buttons ==================== */

.button-group { display: flex; gap: 10px; margin-top: 20px; }

button {
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--purple);
    color: #fff;
    flex: 1;
    height: 80px;
}
.btn-primary:hover {
    background: var(--dark-purple);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(139, 77, 255, 0.35);
}

.btn-secondary {
    background: var(--light-purple);
    color: var(--dark-purple);
}
.btn-secondary:hover { background: #BFBDF8; }

button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }

.link-button {
    background: none;
    border: none;
    color: var(--purple);
    font-size: 0.9em;
    font-weight: 600;
    padding: 4px 6px;
    cursor: pointer;
    text-decoration: underline;
}
.link-button:hover { color: var(--dark-purple); }

/* ==================== Status messages ==================== */

.status-message {
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    margin-top: 20px;
    display: none;
    white-space: pre-wrap;
    max-height: 400px;
    overflow-y: auto;
    border-left: 4px solid transparent;
}
.status-message.success {
    background: rgba(113, 238, 162, 0.22);
    color: #0E5C36;
    border-left-color: var(--green);
}
.status-message.error {
    background: var(--pink);
    color: var(--dark-red);
    border-left-color: var(--dark-red);
}
.status-message.info {
    background: rgba(209, 208, 251, 0.45);
    color: var(--dark-purple);
    border-left-color: var(--purple);
}

/* ==================== Results ==================== */

.results-section { display: none; }
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    gap: 12px;
}
.results-header h2 { margin-bottom: 0; }

.results-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.results-table th {
    background: var(--dark-purple);
    color: #fff;
    padding: 12px;
    text-align: left;
    font-size: 0.9em;
    white-space: nowrap;
}
.results-table th:first-child { border-radius: var(--radius-sm) 0 0 0; }
.results-table th:last-child { border-radius: 0 var(--radius-sm) 0 0; }
.results-table td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 0.93em; }
.results-table tr:hover td { background: rgba(209, 208, 251, 0.22); }

.status-badge {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.78em;
    font-weight: 700;
    letter-spacing: 0.3px;
    white-space: nowrap;
}
.status-badge.clean { background: rgba(113, 238, 162, 0.35); color: #0E5C36; }
.status-badge.locked_by_other { background: var(--dark-red); color: #fff; }
.status-badge.locked_by_us { background: var(--pink); color: var(--dark-red); }
.status-badge.duplicate { background: rgba(209, 208, 251, 0.7); color: var(--dark-purple); }
.status-badge.error { background: rgba(185, 0, 71, 0.12); color: var(--dark-red); }
.status-badge.pending { background: rgba(34, 16, 59, 0.08); color: var(--text-muted); }

.status-badge.job-queued { background: rgba(209, 208, 251, 0.55); color: var(--dark-purple); }
.status-badge.job-running { background: rgba(139, 77, 255, 0.16); color: var(--purple); }
.status-badge.job-complete { background: rgba(113, 238, 162, 0.35); color: #0E5C36; }
.status-badge.job-partial { background: var(--pink); color: var(--dark-red); }
.status-badge.job-failed { background: rgba(185, 0, 71, 0.12); color: var(--dark-red); }

.table-scroll { width: 100%; overflow-x: auto; }

/* Holder of a locked device, from the inventory lookup rather than the
   upload response, so it is visually separate from Knox's own wording. */
.detail-owner {
    display: block;
    margin-top: 4px;
    font-size: 0.88em;
    font-weight: 600;
    color: var(--dark-red);
}

/* Raw Knox payload: one truncated line per row, expanding in place. Capped
   in width and height so a long payload cannot distort the table. */
.knox-raw { max-width: 380px; vertical-align: top; }

.raw-toggle {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    width: 100%;
    padding: 0;
    background: none;
    border: none;
    border-radius: 0;
    font-family: 'Courier New', monospace;
    font-size: 0.82em;
    font-weight: 400;
    color: var(--text-muted);
    text-align: left;
    cursor: pointer;
}
.raw-toggle:hover { color: var(--purple); }
.raw-toggle:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; }

.raw-chevron { flex-shrink: 0; color: var(--purple); line-height: 1.3; }

.raw-preview {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.raw-full {
    margin-top: 8px;
    padding: 10px 12px;
    max-width: 380px;
    max-height: 280px;
    overflow: auto;
    background: rgba(209, 208, 251, 0.25);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    font-size: 0.82em;
    line-height: 1.5;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
}

/* ==================== Job progress ==================== */

.progress-section { display: none; }

.job-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.job-meta code {
    font-family: 'Courier New', monospace;
    background: rgba(209, 208, 251, 0.4);
    color: var(--dark-purple);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.88em;
}
.job-state {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.78em;
    font-weight: 700;
    letter-spacing: 0.3px;
    background: rgba(139, 77, 255, 0.16);
    color: var(--purple);
    text-transform: uppercase;
}

.progress-bar {
    width: 100%;
    height: 10px;
    background: rgba(209, 208, 251, 0.6);
    border-radius: 20px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--purple) 0%, var(--coral) 100%);
    transition: width 0.4s ease;
}
.progress-label { margin-top: 10px; color: var(--text-muted); font-size: 0.92em; }

/* ==================== File upload ==================== */

.file-upload-area {
    border: 2px dashed var(--purple);
    border-radius: var(--radius-sm);
    padding: 30px;
    text-align: center;
    background: rgba(209, 208, 251, 0.2);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}
.file-upload-area:hover { background: rgba(209, 208, 251, 0.4); border-color: var(--dark-purple); }
#fileInput { display: none; }

.file-info {
    margin-top: 15px;
    display: none;
    padding: 12px;
    background: rgba(113, 238, 162, 0.2);
    border-radius: var(--radius-sm);
    font-size: 0.92em;
}

/* ==================== Tabs ==================== */

.tabs { display: flex; gap: 8px; margin-bottom: 20px; border-bottom: 2px solid var(--border); }
.tab {
    padding: 10px 20px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    border-radius: 0;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: -2px;
}
.tab:hover { color: var(--purple); }
.tab.active { color: var(--dark-purple); border-bottom-color: var(--coral); }

.tab-content { display: none; }
.tab-content.active { display: block; }

.export-buttons { display: flex; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }

.hint { color: var(--text-muted); font-size: 0.9em; margin-top: 12px; }

/* Job history: collapsed until opened */
.chevron { display: inline-block; font-size: 0.9em; }

.history-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 16px;
}

.info-box {
    background: rgba(209, 208, 251, 0.3);
    border-left: 4px solid var(--purple);
    padding: 15px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
}

/* ==================== Small screens ==================== */

@media (max-width: 640px) {
    .brand-subtitle { display: none; }
    /* 12px padding + 46px logo = 70px, matching the 20% increase. */
    .brand-logo { width: 46px; height: 46px; }
    /* Truncate rather than push the avatar off a narrow screen. */
    .brand-title {
        font-size: 1.1em;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .app-bar-inner { gap: 10px; }
    .avatar { width: 42px; height: 42px; }
    .app-bar-inner { padding: 12px 16px; }
    .container { padding: 16px 16px 40px; }
    .card { padding: 20px; }
    .button-group { flex-direction: column; }
}
