/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Light mode - colori invertiti rispetto ad Articoli */
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8e8e8;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --border-color: rgba(0, 0, 0, 0.1);
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #22c55e;
    --radius: 8px;
    --radius-lg: 12px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

/* Login Page */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-box {
    width: 100%;
    max-width: 360px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 40px 32px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.login-title {
    font-size: 24px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 32px;
    letter-spacing: 2px;
    color: var(--accent);
}

.login-form .form-group {
    margin-bottom: 20px;
}

.login-form label {
    display: block;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.login-form input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
}

.login-form input:focus {
    border-color: var(--accent);
}

.error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 12px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 14px;
    text-align: center;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: #d8d8d8;
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    color: white;
}

.btn-icon {
    padding: 8px;
    background: transparent;
    color: var(--text-secondary);
}

.btn-icon:hover {
    color: var(--text-primary);
}

.btn-full {
    width: 100%;
}

/* Dashboard Layout */
.dashboard {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 2px;
    color: var(--accent);
}

.template-name {
    font-size: 14px;
    color: var(--text-secondary);
    padding-left: 16px;
    border-left: 1px solid var(--border-color);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 24px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

/* Endpoint Zone */
.endpoint-zone {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.endpoint-zone.loading .endpoint-content {
    opacity: 0.3;
    pointer-events: none;
}

.endpoint-zone.loading .endpoint-loading {
    display: flex;
}

.endpoint-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: opacity 0.2s;
}

.endpoint-input-group {
    display: flex;
    gap: 12px;
}

.endpoint-input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.endpoint-input:focus {
    border-color: var(--accent);
}

.endpoint-input::placeholder {
    color: var(--text-secondary);
}

.endpoint-hint {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
}

.endpoint-loading {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: rgba(255, 255, 255, 0.9);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Fields */
.fields-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.field-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.field-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.field-name {
    font-size: 14px;
    font-weight: 500;
}

.btn-copy {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
}

.btn-copy:hover {
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.05);
}

.btn-copy.copied {
    color: var(--success);
}

.field-value {
    padding: 16px;
    min-height: 56px;
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s;
}

.field-value:hover:not([data-empty="true"]) {
    background: var(--bg-tertiary);
}

.field-value[data-empty="true"] {
    cursor: default;
}

.field-value .placeholder {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 14px;
}

.field-value .value {
    color: var(--text-primary);
    word-break: break-word;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 64px 24px;
    color: var(--text-secondary);
}

.empty-state svg {
    margin-bottom: 24px;
    opacity: 0.5;
}

.empty-state h2 {
    font-size: 18px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.empty-state p {
    font-size: 14px;
}

/* Footer */
.footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    background: var(--bg-secondary);
}

.footer-form {
    display: flex;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 12px 16px;
    min-width: 250px;
    max-width: 350px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.toast.success {
    border-left: 3px solid var(--success);
}

.toast.error {
    border-left: 3px solid var(--danger);
}

.toast-message {
    flex: 1;
    font-size: 14px;
}

.toast-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    font-size: 18px;
    line-height: 1;
}

.toast-close:hover {
    color: var(--text-primary);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Mode Selector */
.mode-selector {
    margin-bottom: 24px;
}

.mode-tabs {
    display: flex;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.mode-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.mode-tab:hover {
    color: var(--text-primary);
}

.mode-tab.active {
    background: var(--accent);
    color: white;
}

/* Mode Panels */
.mode-panel {
    margin-bottom: 24px;
}

.mode-panel.hidden {
    display: none;
}

.panel-header {
    margin-bottom: 16px;
}

.panel-header h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}

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

/* Webhook Info */
.webhook-info {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.info-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
}

.info-row:not(:last-child) {
    border-bottom: 1px solid var(--border-color);
}

.info-label {
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 100px;
}

.info-value {
    flex: 1;
    font-family: monospace;
    font-size: 12px;
    background: var(--bg-tertiary);
    padding: 6px 10px;
    border-radius: 4px;
    word-break: break-all;
}

.token-value {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-copy-small {
    padding: 4px;
    color: var(--text-secondary);
}

.btn-copy-small:hover {
    color: var(--accent);
}

/* Polling Status */
.polling-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 12px 16px;
}

.polling-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--success);
}

.pulse {
    width: 10px;
    height: 10px;
    background: var(--success);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.last-check {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Debug Panel */
.debug-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.debug-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    color: var(--text-secondary);
    transition: color 0.2s;
}

.debug-header:hover {
    color: var(--text-primary);
}

.debug-header svg {
    transition: transform 0.2s;
}

.debug-panel.expanded .debug-header svg {
    transform: rotate(180deg);
}

.debug-content {
    display: none;
    padding: 16px;
    border-top: 1px solid var(--border-color);
}

.debug-panel.expanded .debug-content {
    display: block;
}

.debug-section {
    margin-bottom: 16px;
}

.debug-section:last-child {
    margin-bottom: 0;
}

.debug-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 8px;
}

.debug-section pre {
    background: #1a1a1a;
    color: #e0e0e0;
    padding: 12px;
    border-radius: var(--radius);
    font-size: 11px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 200px;
    overflow-y: auto;
}

/* Fields Section */
.fields-section {
    margin-top: 24px;
}

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

.fields-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.data-status {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.data-status.received {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success);
}

/* Responsive */
@media (max-width: 600px) {
    .header {
        padding: 12px 16px;
    }

    .main-content {
        padding: 16px;
    }

    .endpoint-zone {
        padding: 16px;
    }

    .endpoint-input-group {
        flex-direction: column;
    }

    .template-name {
        display: none;
    }

    .mode-tabs {
        flex-direction: column;
    }

    .info-row {
        flex-wrap: wrap;
    }

    .info-value {
        width: 100%;
        margin-top: 4px;
    }
}
