/* ===========================
   grade.css — Grade It? view
   XP työpöytä + ikkunat
   =========================== */

#view-grade {
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* Sama XP-työpöytä tausta */
.grade-desktop-bg {
    background-image: url('img/background.jpg');
    background-size: cover;
    background-position: center;
    background-color: #008080;
    position: absolute;
    inset: 0;
    bottom: 40px;
    bottom: 40px; /* taskbar */
}

/* Taskbar */
#view-grade .taskbar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 500;
}

.grade-taskbar-title {
    flex: 1;
    color: white;
    font-family: 'Tahoma', sans-serif;
    font-size: 12px;
    font-weight: bold;
    padding: 0 8px;
    display: flex;
    align-items: center;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== DESKTOP ICONS (vasen reuna) ===== */
.grade-icons {
    position: absolute;
    top: 20px;
    left: 20px;
    display: flex;
    flex-direction: column;
    gap: 0;
    z-index: 10;
}

/* ===== GRADE WINDOW (canvas) ===== */
.grade-window {
    position: absolute;
    top: 30px;
    left: 130px;
    width: calc(100vw - 160px);
    height: calc(100vh - 90px); /* taskbar + pieni marginaali */
    background: #F0F0F0;
    border: 3px solid #0078D4;
    box-shadow: 3px 3px 10px rgba(0,0,0,0.4);
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 100;
    min-width: 400px;
    min-height: 300px;
}

.grade-window-header {
    background: linear-gradient(to bottom, #0078D4, #005FA3);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 8px;
    border-bottom: 2px solid #005FA3;
    height: 28px;
    font-size: 13px;
    font-weight: bold;
    cursor: move;
    user-select: none;
    flex-shrink: 0;
}

.grade-window-controls {
    display: flex;
    gap: 4px;
}

.grade-win-btn {
    width: 22px;
    height: 22px;
    border-radius: 3px;
    border: 1px solid rgba(255,255,255,0.5);
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.grade-win-minimize { background: #FFB800; color: #000; border-color: #e0a000; }
.grade-win-close    { background: #FF0000; color: #fff; border-color: #cc0000; }
.grade-win-minimize:hover { background: #FFA500; }
.grade-win-close:hover    { background: #CC0000; }

/* ===== TOOLBAR ===== */
.grade-toolbar {
    background: #D4D0C8;
    border-bottom: 1px solid #808080;
    padding: 4px 6px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 3px;
    font-family: 'Tahoma', sans-serif;
    font-size: 11px;
    flex-shrink: 0;
}

.grade-btn {
    background: linear-gradient(to bottom, #f0f0f0, #d4d0c8);
    border: 2px outset #ffffff;
    border-radius: 2px;
    padding: 2px 7px;
    font-family: 'Tahoma', sans-serif;
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
    color: #000;
    height: 22px;
}

.grade-btn:hover  { background: linear-gradient(to bottom, #e0e8f0, #c0ccd8); }
.grade-btn:active { border-style: inset; }
.grade-btn.active { background: linear-gradient(to bottom, #c0ccd8, #a0b0c0); border-style: inset; }

.grade-btn-primary {
    background: linear-gradient(to bottom, #0078D4, #005FA3);
    border: 2px outset #3399ff;
    border-radius: 3px;
    padding: 3px 10px;
    font-family: 'Tahoma', sans-serif;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    color: white;
    white-space: nowrap;
    height: 22px;
    display: flex;
    align-items: center;
}

.grade-btn-primary:hover { background: linear-gradient(to bottom, #1a8ae0, #0068b4); }

.grade-toolbar-sep {
    width: 1px;
    height: 18px;
    background: #a0a090;
    margin: 0 3px;
    flex-shrink: 0;
}

.grade-guide-label {
    font-size: 10px;
    color: #444;
    font-weight: bold;
    white-space: nowrap;
}

.grade-guide-btn {
    background: linear-gradient(to bottom, #e0f0ff, #c0d8f0);
    border: 2px outset #8ab4d4;
    border-radius: 2px;
    padding: 1px 5px;
    font-family: 'Tahoma', sans-serif;
    font-size: 10px;
    cursor: pointer;
    color: #003366;
    white-space: nowrap;
    height: 20px;
}

.grade-guide-btn.inner {
    background: linear-gradient(to bottom, #fff0e0, #f0d0b0);
    border-color: #d4a060;
    color: #663300;
}

.grade-guide-btn.set {
    background: linear-gradient(to bottom, #90d090, #60b060) !important;
    color: #002200 !important;
    font-weight: bold;
}

.grade-guide-btn:hover { filter: brightness(1.08); }

#straightenSlider {
    width: 80px;
    accent-color: #0078D4;
}

#straightenVal {
    font-size: 11px;
    min-width: 32px;
    color: #333;
}

.grade-zoom-label {
    font-size: 11px;
    min-width: 36px;
    color: #333;
    font-weight: bold;
}

/* ===== MAIN CONTENT AREA ===== */
.grade-main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* ===== CANVAS ===== */
.grade-canvas-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #1a1a2a;
}

.grade-drop-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: #aaa;
    font-family: 'Tahoma', sans-serif;
    font-size: 15px;
    border: 3px dashed #444;
    cursor: pointer;
    transition: all 0.2s;
}

.grade-drop-overlay:hover,
.grade-drop-overlay.dragover {
    border-color: #0078D4;
    color: #66aaff;
    background: rgba(0,120,212,0.05);
}

.grade-drop-overlay > div { pointer-events: none; }

#mainCanvas {
    display: block;
    width: 100%;
    height: 100%;
}

.grade-legend {
    position: absolute;
    bottom: 6px;
    left: 8px;
    display: flex;
    gap: 12px;
    font-family: 'Courier New', monospace;
    font-size: 10px;
    pointer-events: none;
}

.legend-outer  { color: #00d4ff; }
.legend-inner  { color: #ff6b35; }
.legend-center { color: rgba(200,255,0,0.7); }

/* ===== METRICS PANEL ===== */
.grade-metrics-panel {
    width: 210px;
    min-width: 210px;
    background: #F0F0F0;
    border-left: 2px solid #0078D4;
    padding: 8px 6px;
    font-family: 'Tahoma', sans-serif;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.grade-metrics-title {
    font-size: 15px;
    font-weight: bold;
    color: #0078D4;
    border-bottom: 1px solid #ccc;
    padding-bottom: 3px;
}

#centeringMetrics {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.metric-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    padding: 3px 0;
    border-bottom: 1px dotted #ddd;
}

.metric-half { font-family: 'Courier New', monospace; }
.m-ok   { color: #007700; font-weight: bold; }
.m-warn { color: #aa7700; font-weight: bold; }
.m-bad  { color: #cc0000; font-weight: bold; }

.grade-metrics-tip {
    font-size: 12px;
    color: #888;
    font-style: italic;
    line-height: 1.4;
}

.grade-psa-scale  { margin-top: 2px; }
.grade-psa-title  { font-size: 13px; font-weight: bold; color: #555; margin-bottom: 3px; }

.grade-psa-row {
    font-size: 12px;
    padding: 3px 5px;
    border-radius: 2px;
    margin-bottom: 3px;
    font-family: 'Courier New', monospace;
}

.psa-10  { background: #c8ff00; color: #222; }
.psa-9   { background: #7fff7f; color: #222; }
.psa-8   { background: #ffdf5a; color: #222; }
.psa-7   { background: #ff9f3a; color: #222; }
.psa-low { background: #ff5a5a; color: white; font-style: italic; }

/* ===== NOTEPAD IKKUNAT GRADE-NÄKYMÄSSÄ ===== */
#view-grade .notepad-modal {
    z-index: 200;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .grade-icons { display: none; }

    .grade-window {
        left: 0;
        top: 0;
        width: 100vw;
        height: calc(100dvh - 50px);
        max-height: calc(100dvh - 50px);
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: none;
        min-width: unset;
    }

    .grade-window-header {
        font-size: 11px;
        height: 26px;
        padding: 3px 6px;
    }

    .grade-toolbar {
        padding: 3px 4px;
        gap: 2px;
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .grade-btn {
        padding: 2px 5px;
        font-size: 10px;
        height: 20px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .grade-btn-primary {
        padding: 2px 8px;
        font-size: 10px;
        height: 20px;
        flex-shrink: 0;
    }

    .grade-guide-btn {
        padding: 1px 4px;
        font-size: 10px;
        height: 18px;
        flex-shrink: 0;
    }

    .grade-guide-label { display: none; }
    .grade-toolbar-sep { display: none; }

    #straightenSlider { width: 70px; flex-shrink: 0; }
    #straightenVal { min-width: 28px; font-size: 10px; }
    .grade-zoom-label { min-width: 30px; font-size: 10px; }

    .grade-metrics-panel {
        width: 120px;
        min-width: 120px;
        padding: 6px 4px;
        font-size: 11px;
    }

    .grade-metrics-title { font-size: 12px; }
    .metric-row { font-size: 11px; }
    .grade-psa-title { font-size: 11px; }
    .grade-psa-row { font-size: 10px; padding: 2px 3px; }
    .grade-metrics-tip { font-size: 10px; }
}

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

    .grade-canvas-wrap {
        flex: 1;
        min-height: 0;
    }

    .grade-metrics-panel {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        width: 100%;
        min-width: unset;
        height: 120px;
        max-height: 120px;
        overflow-y: auto;
        border-left: none;
        border-top: 2px solid #0078D4;
        padding: 4px 8px;
        gap: 6px;
        flex-shrink: 0;
        box-sizing: border-box;
    }

    .grade-metrics-title {
        width: 100%;
        font-size: 12px;
        margin-bottom: 2px;
    }

    #centeringMetrics {
        flex-direction: row;
        gap: 10px;
    }

    .metric-row { font-size: 12px; }
    .grade-metrics-tip { display: none; }

    .grade-psa-scale {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 3px;
        align-items: center;
    }

    .grade-psa-title { display: none; }

    .grade-psa-row {
        font-size: 10px;
        padding: 2px 4px;
        white-space: nowrap;
        margin-bottom: 0;
    }

    .grade-window-header span:first-child {
        font-size: 10px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: calc(100vw - 70px);
    }
}
