/* Cecile Sheep 3D Viewer - Styles */

:root {
    --primary-color: #2c5aa0;
    --primary-hover: #1e4080;
    --success-color: #28a745;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --background-color: #f5f5f5;
    --panel-bg: #ffffff;
    --border-color: #ddd;
    --text-color: #333;
    --text-muted: #666;
    --header-height: 50px;
    --panel-width: 280px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    color: var(--text-color);
    background-color: var(--background-color);
    overflow: hidden;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.app-header {
    height: var(--header-height);
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.app-header h1 {
    font-size: 18px;
    font-weight: 500;
}

.calibration-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--warning-color);
}

.status-dot.calibrated {
    background: var(--success-color);
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Panels */
.panel {
    width: var(--panel-width);
    background: var(--panel-bg);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 15px;
}

.panel-right {
    border-right: none;
    border-left: 1px solid var(--border-color);
}

.panel h2 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
    color: var(--primary-color);
}

.placeholder {
    color: var(--text-muted);
    font-style: italic;
    font-size: 13px;
}

/* Animal List */
.animal-list {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 20px;
}

.animal-item {
    padding: 8px 10px;
    margin-bottom: 4px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
    transition: background 0.2s;
}

.animal-item:hover {
    background: #e9ecef;
}

.animal-item.active {
    background: var(--primary-color);
    color: white;
}

.animal-item .matricola {
    font-weight: 600;
}

.animal-item .breed {
    font-size: 11px;
    opacity: 0.8;
}

.animal-item .model-count {
    background: rgba(0,0,0,0.1);
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 11px;
}

/* Model List */
.model-list {
    max-height: 250px;
    overflow-y: auto;
}

.model-item {
    padding: 8px 10px;
    margin-bottom: 4px;
    border-radius: 4px;
    cursor: pointer;
    background: #f8f9fa;
    font-size: 13px;
    transition: background 0.2s;
}

.model-item:hover {
    background: #e9ecef;
}

.model-item.active {
    background: var(--primary-color);
    color: white;
}

/* Viewer Container */
.viewer-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #1a1a2e;
}

.viewer-toolbar {
    display: flex;
    gap: 15px;
    padding: 8px 15px;
    background: #2a2a4e;
    border-bottom: 1px solid #3a3a5e;
}

.tool-group {
    display: flex;
    gap: 5px;
}

.tool-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    background: #3a3a5e;
    color: white;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.tool-btn:hover {
    background: #4a4a6e;
}

.tool-btn[data-active="true"],
.tool-btn.active {
    background: var(--primary-color);
}

.tool-btn .icon {
    font-size: 14px;
}

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

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

/* Viewer Canvas */
.viewer-canvas {
    flex: 1;
    position: relative;
}

.viewer-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #666;
    text-align: center;
}

.viewer-canvas canvas {
    width: 100% !important;
    height: 100% !important;
}

.viewer-info {
    display: flex;
    justify-content: space-between;
    padding: 5px 15px;
    background: #2a2a4e;
    color: #aaa;
    font-size: 11px;
    font-family: monospace;
}

/* Animal Info */
.animal-info {
    margin-bottom: 15px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 13px;
}

.info-row .label {
    color: var(--text-muted);
}

.info-row .value {
    font-weight: 500;
}

/* Measurements */
.measurement-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid #eee;
    font-size: 13px;
}

.measurement-row:last-child {
    border-bottom: none;
}

.measurement-row .name {
    flex: 1;
}

.measurement-row .value {
    font-weight: 600;
    color: var(--primary-color);
    min-width: 60px;
    text-align: right;
}

.measurement-row .unit {
    color: var(--text-muted);
    margin-left: 4px;
    font-size: 11px;
}

.measurement-row .actions {
    margin-left: 10px;
}

.measurement-row .btn-delete {
    background: none;
    border: none;
    color: var(--danger-color);
    cursor: pointer;
    padding: 2px 6px;
    font-size: 14px;
}

/* Landmarks Panel */
.landmarks-panel .landmark-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    margin-bottom: 4px;
    background: #f8f9fa;
    border-radius: 4px;
    font-size: 12px;
}

.landmark-item.placed {
    background: #d4edda;
}

.landmark-item .landmark-name {
    flex: 1;
}

.landmark-item .landmark-status {
    font-size: 11px;
    color: var(--text-muted);
}

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

.landmark-item .btn-delete-landmark {
    background: none;
    border: none;
    color: var(--danger-color);
    cursor: pointer;
    padding: 2px 6px;
    font-size: 14px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.landmark-item .btn-delete-landmark:hover {
    opacity: 1;
}

/* Average measurement display */
.measurement-row .avg-value {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: normal;
    margin-left: 5px;
}

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

.modal-content {
    background: white;
    padding: 25px;
    border-radius: 8px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h2 {
    margin-bottom: 15px;
    color: var(--primary-color);
}

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

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* Form Elements */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    font-size: 13px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group input[readonly] {
    background: #f5f5f5;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.btn:hover {
    background: #f5f5f5;
}

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

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-small {
    padding: 2px 8px;
    font-size: 11px;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    background: #f5f5f5;
    cursor: pointer;
    margin-left: 10px;
    vertical-align: middle;
}

.btn-small:hover {
    background: #e0e0e0;
}

/* Measurement Modal */
.measurement-preview {
    background: #f5f5f5;
    padding: 15px;
    border-radius: 4px;
    margin-bottom: 20px;
    text-align: center;
    font-size: 24px;
    font-weight: bold;
    color: var(--primary-color);
}

.measurement-preview .unit {
    font-size: 16px;
    color: var(--text-muted);
}

.angle-choice {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    background: #f8f9fa;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.radio-label:hover {
    background: #e9ecef;
}

.radio-label input[type="radio"] {
    width: 18px;
    height: 18px;
}

.radio-label input[type="radio"]:checked + span {
    color: var(--primary-color);
}

.radio-label:has(input:checked) {
    border-color: var(--primary-color);
    background: #f0f7ff;
}

/* Landmark Grid */
.landmark-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.landmark-grid-item {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
}

.landmark-grid-item:hover {
    border-color: var(--primary-color);
    background: #f0f7ff;
}

.landmark-grid-item.selected {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.landmark-grid-item.placed {
    background: #d4edda;
    border-color: var(--success-color);
}

.landmark-grid-item .landmark-label {
    font-weight: 500;
    font-size: 12px;
}

.landmark-grid-item .landmark-desc {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 4px;
}

.landmark-grid-item.placed .landmark-desc {
    color: var(--success-color);
}

/* Loading */
.loading {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
}

/* 3D Marker styles */
.viewer-marker {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--danger-color);
    border: 2px solid white;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.viewer-marker.landmark {
    background: var(--primary-color);
    width: 14px;
    height: 14px;
}

.viewer-line {
    position: absolute;
    background: var(--danger-color);
    height: 2px;
    transform-origin: left center;
    pointer-events: none;
}

/* Measurement label in 3D space */
.measurement-label-3d {
    position: absolute;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    pointer-events: none;
    white-space: nowrap;
}

/* Auto measurements section */
.auto-measurements {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 2px solid var(--primary-color);
}

.auto-measurements h2 {
    color: var(--success-color);
}

/* Comparison indicator */
.comparison {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    margin-top: 4px;
}

.comparison .diff {
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 500;
}

.comparison .diff.good {
    background: #d4edda;
    color: #155724;
}

.comparison .diff.warning {
    background: #fff3cd;
    color: #856404;
}

.comparison .diff.bad {
    background: #f8d7da;
    color: #721c24;
}

/* Session average display for auto measurements */
.session-avg {
    font-size: 11px;
    color: var(--primary-color);
    background: #f0f7ff;
    padding: 4px 8px;
    border-radius: 3px;
    margin-top: 2px;
    margin-bottom: 4px;
}

/* Editor Controls */
.edit-controls {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(42, 42, 78, 0.95);
    padding: 15px 20px;
    border-radius: 8px;
    color: white;
    min-width: 300px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.edit-controls-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.edit-controls-header span {
    font-weight: 600;
    font-size: 14px;
}

.edit-toggle-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
}

.edit-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.edit-control-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.edit-control-group label {
    font-size: 12px;
    color: #aaa;
}

.edit-control-group input[type="range"] {
    width: 100%;
    cursor: pointer;
}

.edit-control-group select {
    padding: 6px 10px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 13px;
}

.edit-control-group select option {
    background: #2a2a4e;
    color: white;
}

.box-control-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.box-control-row label {
    min-width: 50px;
}

.box-control-row input[type="range"] {
    flex: 1;
}

.box-control-row span {
    min-width: 40px;
    text-align: right;
    font-size: 12px;
    font-family: monospace;
}

/* Edit tool buttons */
.tool-group-edit .btn-cancel {
    background: var(--danger-color);
}

.tool-group-edit .btn-cancel:hover {
    background: #c82333;
}

.tool-group-edit .btn-apply {
    background: var(--success-color);
}

.tool-group-edit .btn-apply:hover {
    background: #218838;
}

/* Display Settings Panel */
.display-settings-wrapper {
    position: relative;
}

.display-settings-panel {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: rgba(42, 42, 78, 0.98);
    border: 1px solid #3a3a5e;
    border-radius: 8px;
    padding: 15px;
    min-width: 220px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    z-index: 100;
}

.display-settings-panel::before {
    content: '';
    position: absolute;
    top: -6px;
    right: 20px;
    width: 10px;
    height: 10px;
    background: rgba(42, 42, 78, 0.98);
    border-left: 1px solid #3a3a5e;
    border-top: 1px solid #3a3a5e;
    transform: rotate(45deg);
}

.display-setting {
    margin-bottom: 12px;
}

.display-setting:last-child {
    margin-bottom: 0;
}

.display-setting label {
    display: block;
    font-size: 11px;
    color: #aaa;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.display-setting input[type="range"] {
    width: calc(100% - 45px);
    height: 4px;
    background: #3a3a5e;
    border-radius: 2px;
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
    vertical-align: middle;
}

.display-setting input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.display-setting input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--primary-hover);
}

.display-setting input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.display-setting span {
    display: inline-block;
    width: 40px;
    text-align: right;
    font-size: 12px;
    color: #fff;
    font-family: monospace;
    vertical-align: middle;
}

/* Login Page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a1a2e 0%, #2a2a4e 100%);
    overflow: auto;
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-box {
    background: var(--panel-bg);
    border-radius: 8px;
    padding: 40px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    text-align: center;
}

.login-box h1 {
    color: var(--primary-color);
    font-size: 32px;
    margin-bottom: 5px;
}

.login-box h2 {
    color: var(--text-muted);
    font-size: 16px;
    font-weight: normal;
    margin-bottom: 30px;
}

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

.login-form input {
    font-size: 16px;
    padding: 12px 15px;
}

.login-error {
    background: #f8d7da;
    color: #721c24;
    padding: 12px 15px;
    border-radius: 4px;
    margin-bottom: 20px;
    font-size: 14px;
}

.btn-login {
    width: 100%;
    padding: 12px 20px;
    font-size: 16px;
    margin-top: 10px;
}

/* Logout button in header */
.logout-btn {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    text-decoration: none;
    transition: background 0.2s;
}

.logout-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.nav-link {
    color: white;
    text-decoration: none;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    font-size: 12px;
    transition: background 0.2s;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.2);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Responsive */
@media (max-width: 1200px) {
    .panel {
        width: 240px;
    }
}

@media (max-width: 900px) {
    .main-content {
        flex-direction: column;
    }

    .panel {
        width: 100%;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .panel-right {
        border-left: none;
        border-top: 1px solid var(--border-color);
    }
}
