/* DooverWorx Brand Styles
   Based on Doover Brand Guidelines 2025 v1.0

   Primary Colors:
   - Blue: #0C71C3
   - Green: #6CBF3A
   - Navy: #142848
   - White: #FFFFFF

   Secondary Colors:
   - Snow: #FAF8FD
   - Nearly Black: #1D1D1B
   - Error Red: #FB3328
*/

:root {
    --color-blue: #0C71C3;
    --color-green: #6CBF3A;
    --color-navy: #142848;
    --color-white: #FFFFFF;
    --color-snow: #FAF8FD;
    --color-slate: #F0F2F5;
    --color-slate-dark: #E4E7EB;
    --color-nearly-black: #1D1D1B;
    --color-error: #FB3328;
    --color-warning: #ffa502;
    --color-text: #142848;
    --color-text-muted: #5A6A7A;
    --border-radius: 4px;
    --border-radius-lg: 8px;
}

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

body {
    font-family: 'Bicyclette', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--color-slate);
    color: var(--color-text);
    min-height: 100vh;
    line-height: 2;
}

#app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    border-bottom: 1px solid var(--color-slate-dark);
    margin-bottom: 30px;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo img {
    height: 40px;
    width: auto;
}

header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--color-blue);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.status {
    padding: 8px 16px;
    border-radius: var(--border-radius);
    font-size: 14px;
    font-weight: 500;
}

.status.disconnected {
    background: var(--color-error);
    color: white;
}

.status.connecting {
    background: var(--color-warning);
    color: var(--color-navy);
}

.status.connected {
    background: var(--color-green);
    color: var(--color-navy);
}

.panel {
    background: var(--color-white);
    border-radius: var(--border-radius-lg);
    padding: 30px;
    margin-bottom: 20px;
    border: 1px solid var(--color-slate-dark);
    box-shadow: 0 2px 8px rgba(20, 40, 72, 0.08);
}

.panel.hidden {
    display: none;
}

.panel h2 {
    font-size: 20px;
    margin-bottom: 10px;
    font-weight: 700;
    color: var(--color-navy);
}

.panel h3 {
    font-size: 16px;
    color: var(--color-text-muted);
    margin-bottom: 15px;
    font-weight: 700;
}

.panel p {
    color: var(--color-text-muted);
    margin-bottom: 20px;
}

.code-input-container {
    display: flex;
    gap: 10px;
    max-width: 300px;
}

#session-code {
    flex: 1;
    padding: 12px 16px;
    font-size: 20px;
    font-family: 'Monaco', 'Consolas', monospace;
    text-transform: uppercase;
    text-align: center;
    letter-spacing: 4px;
    border: 2px solid var(--color-slate-dark);
    border-radius: var(--border-radius);
    background: var(--color-slate);
    color: var(--color-blue);
    outline: none;
}

#session-code:focus {
    border-color: var(--color-blue);
}

#session-code::placeholder {
    color: var(--color-text-muted);
    letter-spacing: 2px;
}

button {
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    background: var(--color-blue);
    color: var(--color-white);
    transition: background 0.2s, transform 0.1s;
}

button:hover {
    background: #0a5fa3;
    transform: translateY(-1px);
}

button:disabled {
    background: rgba(255,255,255,0.2);
    cursor: not-allowed;
    transform: none;
}

button.secondary {
    background: var(--color-slate);
    color: var(--color-navy);
    border: 1px solid var(--color-slate-dark);
}

button.secondary:hover {
    background: var(--color-slate-dark);
}

button.danger {
    background: var(--color-error);
    color: white;
}

button.danger:hover {
    background: #d92920;
}

button.small {
    padding: 8px 16px;
    font-size: 14px;
}

.error {
    color: var(--color-error);
    margin-top: 15px;
    font-size: 14px;
}

.toolbar {
    display: flex;
    gap: 15px;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--color-slate-dark);
}

#session-info {
    flex: 1;
    color: var(--color-text-muted);
}

#session-info strong {
    color: var(--color-blue);
    font-family: 'Monaco', 'Consolas', monospace;
}

/* Manual Connection */
#manual-section {
    margin-bottom: 25px;
    padding-bottom: 25px;
    border-bottom: 1px solid var(--color-slate-dark);
}

.manual-connect-form {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

#manual-host {
    flex: 2;
    min-width: 200px;
    padding: 12px 16px;
    font-size: 16px;
    font-family: 'Monaco', 'Consolas', monospace;
    border: 2px solid var(--color-slate-dark);
    border-radius: var(--border-radius);
    background: var(--color-slate);
    color: var(--color-blue);
    outline: none;
}

#manual-host:focus {
    border-color: var(--color-blue);
}

#manual-host::placeholder {
    color: var(--color-text-muted);
}

#manual-port {
    flex: 1;
    min-width: 100px;
    max-width: 120px;
    padding: 12px 16px;
    font-size: 16px;
    font-family: 'Monaco', 'Consolas', monospace;
    border: 2px solid var(--color-slate-dark);
    border-radius: var(--border-radius);
    background: var(--color-slate);
    color: var(--color-blue);
    outline: none;
    -moz-appearance: textfield;
}

#manual-port::-webkit-outer-spin-button,
#manual-port::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

#manual-port:focus {
    border-color: var(--color-blue);
}

#scan-status {
    color: var(--color-warning);
    margin-bottom: 15px;
}

#devices-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 10px;
}

.device-card {
    background: var(--color-slate);
    border: 1px solid var(--color-slate-dark);
    border-radius: var(--border-radius);
    padding: 15px;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.1s, box-shadow 0.2s;
}

.device-card:hover {
    border-color: var(--color-blue);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(12, 113, 195, 0.15);
}

.device-ip {
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 16px;
    color: var(--color-blue);
    margin-bottom: 8px;
}

.device-ports {
    font-size: 12px;
    color: var(--color-text-muted);
}

.device-ports span {
    display: inline-block;
    background: var(--color-white);
    border: 1px solid var(--color-slate-dark);
    padding: 2px 8px;
    border-radius: var(--border-radius);
    margin-right: 5px;
    margin-top: 5px;
}

/* Tunnels Section */
#tunnels-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--color-slate-dark);
}

#tunnels-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tunnel-card {
    background: var(--color-slate);
    border: 2px solid var(--color-green);
    border-radius: var(--border-radius);
    padding: 15px;
}

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

.tunnel-target {
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 14px;
    color: var(--color-green);
    font-weight: 600;
}

.tunnel-status {
    font-size: 12px;
    padding: 4px 8px;
    border-radius: var(--border-radius);
    background: var(--color-green);
    color: var(--color-white);
    font-weight: 600;
}

.tunnel-status.waiting {
    background: var(--color-warning);
}

.tunnel-connection {
    background: var(--color-navy);
    border-radius: var(--border-radius);
    padding: 12px;
    margin-bottom: 10px;
}

.tunnel-label {
    font-size: 12px;
    color: rgba(255,255,255,0.6);
    margin-bottom: 6px;
}

.tunnel-command {
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 14px;
    color: var(--color-blue);
    word-break: break-all;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.tunnel-command code {
    flex: 1;
    background: rgba(0,0,0,0.2);
    padding: 8px 12px;
    border-radius: var(--border-radius);
    user-select: all;
    color: var(--color-white);
}

.copy-btn {
    padding: 6px 12px;
    font-size: 12px;
    white-space: nowrap;
}

.tunnel-actions {
    display: flex;
    justify-content: flex-end;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(20, 40, 72, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--color-white);
    border: 1px solid var(--color-slate-dark);
    border-radius: var(--border-radius-lg);
    padding: 30px;
    min-width: 300px;
    max-width: 400px;
    box-shadow: 0 8px 32px rgba(20, 40, 72, 0.2);
}

.modal-content h3 {
    color: var(--color-navy);
    margin-bottom: 10px;
}

.modal-content p {
    margin-bottom: 20px;
    color: var(--color-text-muted);
}

#port-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}

.port-btn {
    padding: 10px 20px;
    font-family: 'Monaco', 'Consolas', monospace;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--color-slate-dark);
    border-top-color: var(--color-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* HTTPS Help Collapsible */
.https-help {
    margin-top: 10px;
    border: 1px solid var(--color-slate-dark);
    border-radius: var(--border-radius);
    overflow: hidden;
    background: var(--color-white);
}

.https-help-toggle {
    width: 100%;
    padding: 10px 15px;
    background: var(--color-slate);
    border: none;
    color: var(--color-text-muted);
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}

.https-help-toggle:hover {
    background: var(--color-slate-dark);
    transform: none;
}

.toggle-icon {
    font-size: 16px;
    font-weight: 700;
    transition: transform 0.2s;
}

.https-help.expanded .toggle-icon {
    transform: rotate(45deg);
}

.https-help-content {
    display: none;
    padding: 15px;
    background: var(--color-white);
    font-size: 13px;
    line-height: 1.6;
}

.https-help.expanded .https-help-content {
    display: block;
}

.https-help-content > p {
    margin-bottom: 15px;
    color: var(--color-warning);
    font-weight: 500;
}

.help-option {
    margin-bottom: 15px;
    padding: 12px;
    background: var(--color-slate);
    border-radius: var(--border-radius);
}

.help-option:last-child {
    margin-bottom: 0;
}

.help-option-title {
    font-weight: 600;
    color: var(--color-navy);
    margin-bottom: 8px;
}

.help-option p {
    margin: 8px 0;
    color: var(--color-text-muted);
}

.help-option code {
    background: var(--color-navy);
    color: var(--color-white);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 12px;
}

.help-option .tunnel-command {
    margin-top: 8px;
}

.help-option .tunnel-command code {
    padding: 8px 12px;
    font-size: 11px;
}

/* Responsive */
@media (max-width: 600px) {
    .code-input-container {
        flex-direction: column;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    #session-info {
        text-align: center;
        margin-bottom: 10px;
    }

    .tunnel-command {
        flex-direction: column;
        align-items: stretch;
    }
}
