/* ================= Design Foundation ================= */

:root {
    --color-bg: #0b1115;
    --color-surface: #10181d;
    --color-surface-raised: #141f25;
    --color-surface-hover: #18252c;
    --color-surface-input: #121c21;

    --color-border: #26353c;
    --color-border-strong: #34464f;

    --color-text: #edf4f6;
    --color-text-secondary: #a7b7bd;
    --color-text-muted: #71848c;

    --color-accent: #20c7d4;
    --color-accent-hover: #39d5e0;
    --color-accent-soft: rgba(32, 199, 212, 0.12);
    --color-accent-border: rgba(32, 199, 212, 0.65);

    --color-success: #35d38a;
    --color-warning: #f0b84b;
    --color-error: #ef6262;

    --radius-sm: 4px;
    --radius-md: 6px;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;

    --control-height: 36px;

    --transition-fast: 120ms ease;
}


/* ================= Base ================= */

* {
    box-sizing: border-box;
}

html {
    color-scheme: dark;
}

body {
    display: flex;
    margin: 0;
    height: 100vh;
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    font-size: 14px;
    line-height: 1.5;
    background: var(--color-bg);
    color: var(--color-text);
}

::selection {
    background: var(--color-accent);
    color: #061013;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}


/* ================= Scrollbars ================= */

* {
    scrollbar-width: thin;
    scrollbar-color: var(--color-border-strong) transparent;
}

*::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: var(--color-border-strong);
    border-radius: 10px;
}


/* ================= Application Shell ================= */

.sidebar {
    flex: 0 0 280px;
    width: 280px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: var(--space-5);
    gap: var(--space-5);
    background: #091014;
    border-right: 1px solid var(--color-border);
    overflow-y: auto;
}

.main {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    height: 100vh;
    padding: var(--space-5);
    background: var(--color-bg);
    overflow-y: auto;
}


/* ================= Brand ================= */

#title {
    padding: 4px 0 18px;
}

#title h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1;
    font-weight: 700;
    letter-spacing: -0.045em;
    color: var(--color-text);
}

#title::after {
    content: "API WORKSPACE";
    display: block;
    margin-top: 8px;
    font-size: 9px;
    line-height: 1;
    font-weight: 600;
    letter-spacing: 0.18em;
    color: var(--color-text-muted);
}

/* ================= Section Labels ================= */

.sidebar h2 {
    margin: 0 0 10px;
    font-size: 10px;
    line-height: 1;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}


/* ================= Project Navigation ================= */

#project-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#project-list > li {
    position: relative;
    padding: 9px 10px;
    margin-bottom: 3px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    color: var(--color-text-secondary);
    transition:
        background var(--transition-fast),
        color var(--transition-fast);
}

#project-list > li:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

#project-list > li.selected {
    background: rgba(32, 199, 212, 0.08);
    color: var(--color-text);
}

#project-list > li.selected::before {
    content: "";
    position: absolute;
    left: 0;
    top: 7px;
    bottom: 7px;
    width: 2px;
    background: var(--color-accent);
    border-radius: 2px;
}


/* ================= Project Identity ================= */

.project-name {
    margin-right: 6px;
    color: var(--color-text);
    font-size: 14px;
    font-weight: 600;
}

#project-list > li.selected .project-name {
    color: var(--color-accent-hover);
}

.project-description {
    margin: 3px 0 4px 0;
    padding-left: 0;
    font-size: 12px;
    line-height: 1.4;
    color: var(--color-text-muted);
    font-weight: 400;
    overflow-wrap: anywhere;
}


/* ================= Project Actions ================= */

#project-list > li > button {
    min-height: auto;
    margin-left: 2px;
    padding: 1px 5px;
    font-size: 11px;
    font-weight: 500;
    color: var(--color-text-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    transition:
        color var(--transition-fast),
        background var(--transition-fast),
        border-color var(--transition-fast);
}

#project-list > li > button:hover {
    color: var(--color-text-secondary);
    background: var(--color-surface-raised);
    border-color: var(--color-border);
}

#project-list > li > button:last-of-type:hover {
    color: var(--color-error);
    background: rgba(239, 98, 98, 0.08);
    border-color: rgba(239, 98, 98, 0.25);
}


/* ================= Nested Endpoints ================= */

.endpoint-list {
    list-style: none;
    margin: 8px 0 0 5px;
    padding-left: 14px;
    border-left: 1px solid var(--color-border);
}

.endpoint-list li {
    position: relative;
    padding: 7px 8px;
    margin-bottom: 2px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    color: var(--color-text-secondary);
    font-size: 13px;
    transition:
        background var(--transition-fast),
        color var(--transition-fast);
}

.endpoint-list li:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.endpoint-list li.selected {
    background: rgba(32, 199, 212, 0.10);
    color: var(--color-text);
}

.endpoint-list li.selected::before {
    content: "";
    position: absolute;
    left: -15px;
    top: 5px;
    bottom: 5px;
    width: 2px;
    background: var(--color-accent);
    border-radius: 2px;
}

.endpoint-name {
    margin-right: 5px;
}

.endpoint-list li.selected .endpoint-name {
    color: var(--color-accent-hover);
}


/* ================= Endpoint Actions ================= */

.endpoint-list li button {
    min-height: auto;
    margin-left: 1px;
    padding: 1px 4px;
    font-size: 10px;
    color: var(--color-text-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
}

.endpoint-list li button:hover {
    color: var(--color-text-secondary);
    background: var(--color-surface-raised);
    border-color: var(--color-border);
}

.endpoint-list li button:last-of-type:hover {
    color: var(--color-error);
    background: rgba(239, 98, 98, 0.08);
    border-color: rgba(239, 98, 98, 0.25);
}


/* ================= Project Editing ================= */

.project-edit-input {
    width: 100%;
    margin-bottom: var(--space-2);
    padding: var(--space-2) var(--space-3);
}

.project-edit-description {
    width: 100%;
    min-height: 70px;
    margin-bottom: var(--space-2);
    padding: var(--space-2) var(--space-3);
    resize: vertical;
}


/* ================= New Project ================= */

.create-pro {
    position: relative;
    margin-top: auto;
    padding-top: 18px;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    border-top: 1px solid var(--color-border);
}

.create-pro::before {
    content: "NEW PROJECT";
    display: block;
    margin-bottom: 5px;
    font-size: 10px;
    line-height: 1;
    font-weight: 600;
    letter-spacing: 0.18em;
    color: var(--color-text-muted);
}

#pro-input {
    width: 100%;
    height: var(--control-height);
    padding: var(--space-2) var(--space-3);
}

#pro-description-input {
    width: 100%;
    min-height: 78px;
    padding: var(--space-2) var(--space-3);
    resize: vertical;
}

.create-pro #pro-button {
    width: 100%;
    margin-top: 2px;
}


/* ================= Workspace ================= */

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1.7fr) minmax(320px, 0.9fr);
    gap: var(--space-4);
    width: 100%;
    align-items: start;
}


/* ================= Request Builder ================= */

.request-builder {
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border: 1px solid rgba(52, 70, 79, 0.72);
    border-radius: 6px;
    overflow: hidden;
}


/* ================= Response Viewer ================= */

.response-viewer {
    min-width: 0;
    min-height: 600px;
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border: 1px solid rgba(52, 70, 79, 0.72);
    border-radius: 6px;
    overflow: hidden;
    position: sticky;
    top: var(--space-5);
}


/* ================= Request Identity ================= */

.request-top {
    display: grid;
    grid-template-columns:
        110px
        minmax(180px, 1fr)
        180px
        90px
        90px;
    gap: var(--space-2);
    align-items: end;
    padding: 16px;
    background: var(--color-surface-raised);
    border-bottom: 1px solid var(--color-border-strong);
}

.method-section,
.url-section,
.endpoint-name-section,
.save-section,
.send-section {
    min-width: 0;
}

.method-section,
.url-section,
.endpoint-name-section,
.save-section,
.send-section {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: var(--space-1);
}

.save-section,
.send-section {
    justify-content: flex-end;
}


/* ================= Typography ================= */

label {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--color-text-secondary);
}

h3 {
    margin: 0;
    font-size: 16px;
    line-height: 1.3;
    font-weight: 600;
    color: var(--color-text);
}

.method-section label,
.url-section label,
.endpoint-name-section label {
    letter-spacing: 0.01em;
}


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

input,
select,
textarea {
    color: var(--color-text);
    background: var(--color-surface-input);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
}

.request-builder input,
.request-builder select,
.request-builder textarea,
.create-pro input,
.create-pro textarea,
.project-edit-input,
.project-edit-description {
    width: 100%;
}

.request-builder input,
.request-builder select {
    height: var(--control-height);
    padding: var(--space-2) var(--space-3);
}

.request-builder textarea {
    padding: var(--space-3);
}

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

input:hover,
select:hover,
textarea:hover {
    border-color: var(--color-border-strong);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px var(--color-accent-soft);
}

button {
    min-height: var(--control-height);
    padding: var(--space-2) var(--space-3);
    color: var(--color-text);
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition:
        background var(--transition-fast),
        border-color var(--transition-fast),
        color var(--transition-fast),
        transform var(--transition-fast);
}

button:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-accent-border);
}

button:active {
    transform: translateY(1px);
}

button:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}


/* ================= Primary Actions ================= */

#save-endpoint-btn,
#send-btn {
    width: 100%;
    height: var(--control-height);
}

#save-endpoint-btn {
    color: var(--color-text-secondary);
    background: transparent;
    border-color: var(--color-border-strong);
}

#save-endpoint-btn:hover {
    color: var(--color-text);
    background: var(--color-surface-hover);
    border-color: var(--color-accent-border);
}

#send-btn {
    position: relative;
    color: #061013;
    background: var(--color-accent);
    border-color: var(--color-accent);
    font-weight: 700;
    box-shadow: 0 0 0 1px rgba(32, 199, 212, 0.12);
}

#send-btn:hover {
    color: #061013;
    background: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
    box-shadow: 0 0 0 2px var(--color-accent-soft);
}

.create-pro button {
    color: #061013;
    background: var(--color-accent);
    border-color: var(--color-accent);
    font-weight: 600;
}

.create-pro button:hover {
    color: #061013;
    background: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
}

.request-builder input,
.request-builder select,
.request-builder textarea,
.create-pro input,
.create-pro textarea,
.project-edit-input,
.project-edit-description {
    width: 100%;
}

.request-builder input,
.request-builder select {
    height: var(--control-height);
    padding: var(--space-2) var(--space-3);
}

.request-builder textarea {
    padding: var(--space-3);
}

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

input:hover,
select:hover,
textarea:hover {
    border-color: var(--color-border-strong);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px var(--color-accent-soft);
}

button {
    min-height: var(--control-height);
    padding: var(--space-2) var(--space-3);
    color: var(--color-text);
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition:
        background var(--transition-fast),
        border-color var(--transition-fast),
        color var(--transition-fast),
        transform var(--transition-fast);
}

button:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-accent-border);
}

button:active {
    transform: translateY(1px);
}

button:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

#save-endpoint-btn,
#send-btn {
    width: 100%;
    height: var(--control-height);
}

#save-endpoint-btn {
    color: var(--color-text-secondary);
    background: transparent;
    border-color: var(--color-border-strong);
}

#save-endpoint-btn:hover {
    color: var(--color-text);
    background: var(--color-surface-hover);
    border-color: var(--color-accent-border);
}

#send-btn,
.create-pro button {
    color: #061013;
    background: var(--color-accent);
    border-color: var(--color-accent);
    font-weight: 600;
}

#send-btn:hover,
.create-pro button:hover {
    color: #061013;
    background: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
}


/* ================= Request Controls ================= */

#method {
    font-weight: 600;
    letter-spacing: 0.01em;
    border-color: var(--color-border-strong);
}

#method:focus {
    border-color: var(--color-accent);
}

#url {
    font-size: 14px;
}


/* ================= Request Metadata ================= */

.endpoint-description-section {
    padding: 18px 16px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.endpoint-description-section label {
    display: block;
    margin-bottom: var(--space-2);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
}

.endpoint-description-section textarea {
    min-height: 88px;
}


/* ================= Request Configuration ================= */

.params-section,
.headers-section,
.body-section {
    min-height: 0;
    padding: 18px 16px;
}

.params-section,
.headers-section {
    border-bottom: 1px solid var(--color-border);
}

.params-section h3,
.headers-section h3,
.body-section h3 {
    margin-bottom: 14px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

textarea {
    min-height: 140px;
    resize: vertical;
}


/* ================= Param / Header Rows ================= */

.param-row,
.header-row {
    display: grid;
    grid-template-columns:
        minmax(0, 1fr)
        minmax(0, 1fr)
        auto;
    gap: var(--space-2);
    align-items: center;
    margin-bottom: var(--space-2);
}

.param-row input,
.header-row input {
    width: 100%;
    min-width: 0;
}

.param-row button,
.header-row button {
    min-width: 70px;
}


/* ================= Add Row Actions ================= */

#add-param-btn,
#add-headers-btn {
    margin-top: var(--space-1);
    color: var(--color-accent);
    background: transparent;
    border-color: var(--color-accent-border);
}

#add-param-btn:hover,
#add-headers-btn:hover {
    color: var(--color-accent-hover);
    background: var(--color-accent-soft);
    border-color: var(--color-accent);
}


/* ================= Body Editor ================= */

.body-section {
    display: flex;
    flex-direction: column;
    flex: 1;
}

#request-body {
    flex: 1;
    min-height: 180px;
    padding: 16px;
    color: #d7e3e7;
    background: #091014;
    border-color: var(--color-border);
    font-family:
        ui-monospace,
        SFMono-Regular,
        "Cascadia Code",
        Consolas,
        monospace;
    font-size: 13px;
    letter-spacing: 0.01em;
    line-height: 1.65;
}

#request-body::placeholder {
    font-family:
        ui-monospace,
        SFMono-Regular,
        "Cascadia Code",
        Consolas,
        monospace;
}


/* ================= Response Status ================= */

.status-section {
    min-height: 104px;
    padding: 18px 16px;
    background: var(--color-surface-raised);
    border-bottom: 1px solid var(--color-border);
}

.status-section h3 {
    margin-bottom: 10px;
}

#status-output {
    display: inline-flex;
    align-items: center;
    margin: 0;
    padding: 5px 10px;
    font-size: 13px;
    font-weight: 700;
    color: var(--color-text-secondary);
    background: var(--color-surface-input);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
}

#status-output.status-success {
    color: var(--color-success);
    background: rgba(53, 211, 138, 0.08);
    border-color: rgba(53, 211, 138, 0.25);
}

#status-output.status-warning {
    color: var(--color-warning);
    background: rgba(240, 184, 75, 0.08);
    border-color: rgba(240, 184, 75, 0.25);
}

#status-output.status-error {
    color: var(--color-error);
    background: rgba(239, 98, 98, 0.08);
    border-color: rgba(239, 98, 98, 0.25);
}

#status-output.status-loading {
    color: var(--color-accent);
    background: var(--color-accent-soft);
    border-color: var(--color-accent-border);
}


/* ================= Response Body ================= */

.json-section {
    flex: 1;
    min-width: 0;
    min-height: 400px;
    padding: 18px 16px 16px;
    display: flex;
    flex-direction: column;
}

.json-section h3 {
    margin-bottom: 14px;
}

#response-output {
    flex: 1;
    min-height: 330px;
    margin: 0;
    padding: 16px;
    overflow: auto;
    white-space: pre-wrap;
    text-align: left;
    word-break: break-word;
    color: #d7e3e7;
    background: #091014;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family:
        ui-monospace,
        SFMono-Regular,
        "Cascadia Code",
        Consolas,
        monospace;
    font-size: 13px;
    letter-spacing: 0.01em;
    line-height: 1.65;
}


/* ================= Execution History ================= */

.history-panel {
    grid-column: 1 / -1;
    min-width: 0;
    padding: 18px 16px;
    background: var(--color-surface);
    border: 1px solid rgba(52, 70, 79, 0.72);
    border-radius: 6px;
    overflow: hidden;
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.history-header h3 {
    margin: 0;
    font-size: 15px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    max-height: 240px;
    overflow-y: auto;
}

.history-item {
    display: grid;
    grid-template-columns: 72px 84px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-top: 1px solid var(--color-border);
    cursor: pointer;
    transition:
        background var(--transition-fast),
        color var(--transition-fast);
}

.history-item:hover {
    background: var(--color-surface-hover);
}

.history-item.selected {
    background: var(--color-accent-soft);
    box-shadow: inset 2px 0 0 var(--color-accent);
}

.history-item.selected .history-status {
    color: var(--color-accent-hover);
}

.history-status {
    font-weight: 700;
}

.history-item.status-success .history-status {
    color: var(--color-success);
}

.history-item.status-warning .history-status {
    color: var(--color-warning);
}

.history-item.status-error .history-status {
    color: var(--color-error);
}

.history-time {
    font-size: 13px;
    color: var(--color-text-secondary);
}

.history-date {
    font-size: 13px;
    color: var(--color-text-muted);
}

.history-empty,
.history-error {
    margin: 0;
    padding: 14px 12px;
    color: var(--color-text-muted);
}

.history-error {
    color: var(--color-error);
}

#refresh-history-btn {
    color: var(--color-text-secondary);
    background: transparent;
}

#refresh-history-btn:hover {
    color: var(--color-text);
    background: var(--color-surface-hover);
    border-color: var(--color-border-strong);
}

/* ================= Responsive Safety ================= */

@media (max-width: 900px) {

    .request-top {
        grid-template-columns:
            repeat(2, minmax(0, 1fr));
    }

    .url-section {
        grid-column: span 2;
    }

    .save-section,
    .send-section {
        min-width: 0;
    }
}


@media (max-width: 700px) {

    body {
        height: auto;
        min-height: 100vh;
        flex-direction: column;
    }

    .sidebar,
    .main {
        width: 100%;
        flex: none;
        height: auto;
    }

    .sidebar {
        min-height: auto;
    }

    .main {
        padding: var(--space-4);
    }

    .workspace {
        flex-direction: column;
    }

    .request-builder,
    .response-viewer,
    .history-panel {
        width: 100%;
    }

    .request-top {
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }

    .url-section {
        grid-column: auto;
    }

    .param-row,
    .header-row {
        grid-template-columns: 1fr;
    }
}



/* ================= E3 Layout Refinement ================= */

@media (max-width: 1100px) {

    .workspace {
        grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.9fr);
    }

    .request-top {
        grid-template-columns:
            100px
            minmax(160px, 1fr)
            160px
            80px
            80px;
    }
}