/* === Reset & Base === */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
                 Ubuntu, Cantarell, sans-serif;
    background: #121212;
    color: #e0e0e0;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

/* === Header / Patient Info === */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #1e1e1e;
    padding: 12px 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
}

.header__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.header__title {
    font-size: 18px;
    font-weight: 600;
    text-align: left;
    color: #ffffff;
}

.patient-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.patient-form__field {
    flex: 1 1 140px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.patient-form__label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: #9e9e9e;
}

.patient-form__input {
    padding: 8px 10px;
    border: 1px solid #333;
    border-radius: 8px;
    background: #2a2a2a;
    color: #fff;
    font-size: 15px;
    outline: none;
    transition: border-color .2s;
}

.patient-form__input:focus {
    border-color: #4fc3f7;
}

/* === Main Area === */
.main {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    gap: 16px;
}

/* === Start Camera Button === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 28px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s, transform .1s;
    -webkit-user-select: none;
    user-select: none;
}

.btn:active {
    transform: scale(.96);
}

.btn--primary {
    background: #4fc3f7;
    color: #000;
}

.btn--primary:hover {
    background: #39b0e6;
}

.btn--primary:disabled {
    background: #555;
    color: #999;
    cursor: not-allowed;
}

.btn--danger {
    background: #ef5350;
    color: #fff;
}

.btn--danger:hover {
    background: #d32f2f;
}

.btn__icon {
    width: 22px;
    height: 22px;
}

/* === Camera Container === */
.camera {
    display: none;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 640px;
    gap: 12px;
}

.camera--active {
    display: flex;
}

.camera__viewport {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    touch-action: none;          /* prevent browser gestures */
    transition: aspect-ratio .3s ease;
}

/* Aspect-ratio modifiers */
.camera__viewport--4-3  { aspect-ratio: 4 / 3; }
.camera__viewport--1-1  { aspect-ratio: 1 / 1; }
.camera__viewport--16-9 { aspect-ratio: 16 / 9; }

.camera__video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform-origin: center center;
    transition: transform .05s linear, filter .25s ease;
}

/* B&W filter */
.camera__video--bw {
    filter: grayscale(100%);
}

/* === Grid Overlay (rule of thirds) === */
.camera__grid {
    position: absolute;
    inset: 0;
    display: none;
    pointer-events: none;
    z-index: 2;
}

.camera__grid--visible {
    display: block;
}

.camera__grid .grid-h {
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(255, 255, 255, .35);
}

.camera__grid .grid-h:nth-child(1) { top: 33.33%; }
.camera__grid .grid-h:nth-child(2) { top: 66.66%; }

.camera__grid .grid-v {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: rgba(255, 255, 255, .35);
}

.camera__grid .grid-v:nth-child(3) { left: 33.33%; }
.camera__grid .grid-v:nth-child(4) { left: 66.66%; }

/* === Horizon Level Indicator === */
.camera__horizon {
    position: absolute;
    left: 5%;
    right: 5%;
    top: 50%;
    height: 2px;
    background: #f44336;          /* red — far from level */
    transform: translateY(-50%) rotate(0deg);
    transform-origin: center center;
    pointer-events: none;
    z-index: 3;
    display: none;
    opacity: .85;
    transition: background .2s;
    border-radius: 1px;
    box-shadow: 0 0 4px rgba(0,0,0,.4);
}

.camera__horizon--visible {
    display: block;
}

.camera__horizon--warn {
    background: #ffea00;          /* yellow — slightly off */
}

.camera__horizon--level {
    background: #00e676;          /* green — level */
}

/* === Camera Toolbar === */
.camera__toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 4px 0;
    flex-wrap: wrap;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 36px;
    padding: 0 10px;
    border: 1px solid #444;
    border-radius: 8px;
    background: rgba(255, 255, 255, .08);
    color: #ccc;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all .2s;
    -webkit-user-select: none;
    user-select: none;
}

.toolbar-btn:hover {
    background: rgba(255, 255, 255, .15);
}

.toolbar-btn--active {
    background: rgba(79, 195, 247, .25);
    border-color: #4fc3f7;
    color: #4fc3f7;
}

.toolbar-btn--disabled,
.toolbar-btn:disabled {
    opacity: .35;
    cursor: not-allowed;
    pointer-events: none;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: #444;
    margin: 0 4px;
}

/* Zoom indicator */
.camera__zoom-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, .55);
    color: #fff;
    font-size: 13px;
    padding: 3px 10px;
    border-radius: 20px;
    pointer-events: none;
    opacity: 0;
    transition: opacity .3s;
}

.camera__zoom-badge--visible {
    opacity: 1;
}

/* === Capture Controls === */
.camera__controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 8px 0;
}

.capture-btn {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    border: 4px solid #fff;
    background: transparent;
    cursor: pointer;
    position: relative;
    transition: transform .15s;
}

.capture-btn::after {
    content: '';
    position: absolute;
    inset: 5px;
    border-radius: 50%;
    background: #fff;
    transition: background .15s;
}

.capture-btn:active {
    transform: scale(.9);
}

.capture-btn:active::after {
    background: #bbb;
}

/* === Hidden Canvas === */
.camera__canvas {
    display: none;
}

/* === Gallery / Captured Photos === */
.gallery {
    width: 100%;
    max-width: 640px;
    margin-top: 8px;
}

.gallery__title {
    font-size: 14px;
    color: #9e9e9e;
    margin-bottom: 8px;
}

.gallery__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
}

.gallery__item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 4/3;
    background: #1e1e1e;
}

.gallery__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: pointer;
}

.gallery__delete {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, .6);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity .2s;
}

.gallery__item:hover .gallery__delete {
    opacity: 1;
}

/* On touch devices always show delete */
@media (hover: none) {
    .gallery__delete {
        opacity: 1;
    }
}

/* === Lightbox (full-screen preview) === */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(0, 0, 0, .92);
    align-items: center;
    justify-content: center;
}

.lightbox--open {
    display: flex;
}

.lightbox__img {
    max-width: 95vw;
    max-height: 90vh;
    border-radius: 8px;
}

.lightbox__close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, .15);
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* === Flash Effect === */
.flash {
    position: fixed;
    inset: 0;
    background: #fff;
    z-index: 400;
    pointer-events: none;
    animation: flash-anim .15s ease-out forwards;
}

@keyframes flash-anim {
    from { opacity: .8; }
    to   { opacity: 0; }
}

/* === Upload Toast === */
.upload-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(120px);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 12px;
    background: #1e1e1e;
    border: 1px solid #333;
    color: #e0e0e0;
    font-size: 14px;
    z-index: 600;
    transition: transform .35s ease;
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(0,0,0,.5);
}

.upload-toast--visible {
    transform: translateX(-50%) translateY(0);
}

.upload-toast--success {
    border-color: #43a047;
    background: #1b2e1b;
}

.upload-toast--error {
    border-color: #ef5350;
    background: #2e1b1b;
}

.upload-toast__icon {
    font-size: 18px;
}

.upload-toast__text {
    white-space: nowrap;
}

/* === OneDrive badge in header === */
.onedrive-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #81c784;
    white-space: nowrap;
}

.onedrive-badge__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #43a047;
}

.onedrive-badge--off {
    color: #9e9e9e;
}

.onedrive-badge--off .onedrive-badge__dot {
    background: #555;
}

/* === Responsive === */
@media (max-width: 480px) {
    .header {
        padding: 10px 12px;
    }

    .patient-form__input {
        font-size: 14px;
        padding: 7px 8px;
    }

    .camera__viewport {
        border-radius: 8px;
    }

    .capture-btn {
        width: 60px;
        height: 60px;
    }
}
